Commit 77b54988c00876752a94b8a2ddbc670f927fcf2c
1 parent
cdae5167
Exists in
master
and in
28 other branches
Validates that a track has at least one category
Showing
9 changed files
with
64 additions
and
56 deletions
Show diff stats
plugins/community_track/lib/community_track_plugin/track.rb
@@ -3,6 +3,12 @@ class CommunityTrackPlugin::Track < Folder | @@ -3,6 +3,12 @@ class CommunityTrackPlugin::Track < Folder | ||
3 | settings_items :goals, :type => :string | 3 | settings_items :goals, :type => :string |
4 | settings_items :expected_results, :type => :string | 4 | settings_items :expected_results, :type => :string |
5 | 5 | ||
6 | + validate :validate_categories | ||
7 | + | ||
8 | + def validate_categories | ||
9 | + errors.add(:categories, _('should not be blank.')) if categories.empty? && pending_categorizations.blank? | ||
10 | + end | ||
11 | + | ||
6 | def self.icon_name(article = nil) | 12 | def self.icon_name(article = nil) |
7 | 'community-track' | 13 | 'community-track' |
8 | end | 14 | end |
plugins/community_track/test/functional/community_track_plugin_cms_controller_test.rb
@@ -7,7 +7,7 @@ class CmsControllerTest < ActionController::TestCase | @@ -7,7 +7,7 @@ class CmsControllerTest < ActionController::TestCase | ||
7 | 7 | ||
8 | def setup | 8 | def setup |
9 | @profile = fast_create(Community) | 9 | @profile = fast_create(Community) |
10 | - @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @profile) | 10 | + @track = create_track('track', @profile) |
11 | @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) | 11 | @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) |
12 | 12 | ||
13 | user = create_user('testinguser') | 13 | user = create_user('testinguser') |
plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb
@@ -11,10 +11,7 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -11,10 +11,7 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
11 | 11 | ||
12 | def setup | 12 | def setup |
13 | @profile = fast_create(Community) | 13 | @profile = fast_create(Community) |
14 | - @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @profile) | ||
15 | - category = fast_create(Category, :name => "education") | ||
16 | - @track.add_category(category) | ||
17 | - | 14 | + @track = create_track('track', @profile) |
18 | @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today, :tool_type => TinyMceArticle.name) | 15 | @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today, :tool_type => TinyMceArticle.name) |
19 | 16 | ||
20 | user = create_user('testinguser') | 17 | user = create_user('testinguser') |
@@ -110,7 +107,7 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -110,7 +107,7 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
110 | @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box) | 107 | @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box) |
111 | @profile.boxes << box | 108 | @profile.boxes << box |
112 | get :view_page, @step.url | 109 | get :view_page, @step.url |
113 | - assert_tag :tag => 'div', :attributes => { :class => 'item category_education' }, :descendant => { :tag => 'div', :attributes => { :class => 'steps' }, :descendant => { :tag => 'div', :attributes => { :class => "step #{@block.status_class(@step)}" } } } | 110 | + assert_tag :tag => 'div', :attributes => { :class => "item category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'steps' }, :descendant => { :tag => 'div', :attributes => { :class => "step #{@block.status_class(@step)}" } } } |
114 | end | 111 | end |
115 | 112 | ||
116 | should 'render tracks in track card list block' do | 113 | should 'render tracks in track card list block' do |
@@ -118,8 +115,8 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -118,8 +115,8 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
118 | @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) | 115 | @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) |
119 | @profile.boxes << box | 116 | @profile.boxes << box |
120 | get :view_page, @step.url | 117 | get :view_page, @step.url |
121 | - assert_tag :tag => 'div', :attributes => { :class => 'item_card category_education' }, :descendant => { :tag => 'div', :attributes => { :class => 'track_content' } } | ||
122 | - assert_tag :tag => 'div', :attributes => { :class => 'item_card category_education' }, :descendant => { :tag => 'div', :attributes => { :class => 'track_stats' } } | 118 | + assert_tag :tag => 'div', :attributes => { :class => "item_card category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'track_content' } } |
119 | + assert_tag :tag => 'div', :attributes => { :class => "item_card category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'track_stats' } } | ||
123 | end | 120 | end |
124 | 121 | ||
125 | should 'render link to display more tracks in track list block' do | 122 | should 'render link to display more tracks in track list block' do |
@@ -127,9 +124,7 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -127,9 +124,7 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
127 | @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) | 124 | @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) |
128 | @profile.boxes << box | 125 | @profile.boxes << box |
129 | 126 | ||
130 | - (@block.limit+1).times do |i| | ||
131 | - CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @profile) | ||
132 | - end | 127 | + (@block.limit+1).times { |i| create_track("track#{i}", @profile) } |
133 | 128 | ||
134 | get :view_page, @step.url | 129 | get :view_page, @step.url |
135 | assert_tag :tag => 'div', :attributes => { :id => "track_list_more_#{@block.id}" }, :descendant => { :tag => 'div', :attributes => { :class => 'more' } } | 130 | assert_tag :tag => 'div', :attributes => { :id => "track_list_more_#{@block.id}" }, :descendant => { :tag => 'div', :attributes => { :class => 'more' } } |
@@ -142,9 +137,7 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -142,9 +137,7 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
142 | @block.more_another_page = true | 137 | @block.more_another_page = true |
143 | @block.save! | 138 | @block.save! |
144 | 139 | ||
145 | - (@block.limit+1).times do |i| | ||
146 | - CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @profile) | ||
147 | - end | 140 | + (@block.limit+1).times { |i| create_track("track#{i}", @profile) } |
148 | 141 | ||
149 | get :view_page, @step.url | 142 | get :view_page, @step.url |
150 | assert_tag :tag => 'div', :attributes => { :id => "track_list_more_#{@block.id}" }, :descendant => { :tag => 'div', :attributes => { :class => 'view_all' } } | 143 | assert_tag :tag => 'div', :attributes => { :id => "track_list_more_#{@block.id}" }, :descendant => { :tag => 'div', :attributes => { :class => 'view_all' } } |
plugins/community_track/test/functional/community_track_plugin_myprofile_controller_test.rb
@@ -12,7 +12,7 @@ class CommunityTrackPluginMyprofileControllerTest < ActionController::TestCase | @@ -12,7 +12,7 @@ class CommunityTrackPluginMyprofileControllerTest < ActionController::TestCase | ||
12 | @response = ActionController::TestResponse.new | 12 | @response = ActionController::TestResponse.new |
13 | 13 | ||
14 | @profile = fast_create(Community) | 14 | @profile = fast_create(Community) |
15 | - @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @profile) | 15 | + @track = create_track('track', @profile) |
16 | 16 | ||
17 | @user = create_user('testinguser') | 17 | @user = create_user('testinguser') |
18 | login_as(@user.login) | 18 | login_as(@user.login) |
plugins/community_track/test/functional/community_track_plugin_public_controller_test.rb
@@ -8,7 +8,7 @@ class CommunityTrackPluginPublicControllerTest < ActionController::TestCase | @@ -8,7 +8,7 @@ class CommunityTrackPluginPublicControllerTest < ActionController::TestCase | ||
8 | 8 | ||
9 | def setup | 9 | def setup |
10 | @community = fast_create(Community) | 10 | @community = fast_create(Community) |
11 | - @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @community) | 11 | + @track = create_track('track', @community) |
12 | 12 | ||
13 | box = fast_create(Box, :owner_id => @community.id, :owner_type => 'Community') | 13 | box = fast_create(Box, :owner_id => @community.id, :owner_type => 'Community') |
14 | @card_block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) | 14 | @card_block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box) |
@@ -26,17 +26,13 @@ class CommunityTrackPluginPublicControllerTest < ActionController::TestCase | @@ -26,17 +26,13 @@ class CommunityTrackPluginPublicControllerTest < ActionController::TestCase | ||
26 | end | 26 | end |
27 | 27 | ||
28 | should 'display tracks with page size' do | 28 | should 'display tracks with page size' do |
29 | - 20.times do |i| | ||
30 | - track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community) | ||
31 | - end | 29 | + 20.times { |i| create_track("track#{i}", @community) } |
32 | xhr :get, :view_tracks, :id => @block.id, :page => 1, :per_page => 10 | 30 | xhr :get, :view_tracks, :id => @block.id, :page => 1, :per_page => 10 |
33 | assert_equal 10, @response.body.scan(/item/).size | 31 | assert_equal 10, @response.body.scan(/item/).size |
34 | end | 32 | end |
35 | 33 | ||
36 | should 'default page size is the block limit' do | 34 | should 'default page size is the block limit' do |
37 | - 20.times do |i| | ||
38 | - track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community) | ||
39 | - end | 35 | + 20.times { |i| create_track("track#{i}", @community) } |
40 | xhr :get, :view_tracks, :id => @block.id, :page => 1 | 36 | xhr :get, :view_tracks, :id => @block.id, :page => 1 |
41 | assert_equal @block.limit, @response.body.scan(/item/).size | 37 | assert_equal @block.limit, @response.body.scan(/item/).size |
42 | end | 38 | end |
@@ -47,9 +43,7 @@ class CommunityTrackPluginPublicControllerTest < ActionController::TestCase | @@ -47,9 +43,7 @@ class CommunityTrackPluginPublicControllerTest < ActionController::TestCase | ||
47 | end | 43 | end |
48 | 44 | ||
49 | should 'show more link in all tracks if there is no more tracks to show' do | 45 | should 'show more link in all tracks if there is no more tracks to show' do |
50 | - 10.times do |i| | ||
51 | - CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community) | ||
52 | - end | 46 | + 10.times { |i| create_track("track#{i}", @community) } |
53 | get :all_tracks, :id => @block.id | 47 | get :all_tracks, :id => @block.id |
54 | assert assigns['show_more'] | 48 | assert assigns['show_more'] |
55 | assert_match /track_list_more_#{@block.id}/, @response.body | 49 | assert_match /track_list_more_#{@block.id}/, @response.body |
plugins/community_track/test/test_helper.rb
1 | require File.dirname(__FILE__) + '/../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../test/test_helper' |
2 | + | ||
3 | +def create_track(name, profile) | ||
4 | + track = CommunityTrackPlugin::Track.new(:abstract => 'abstract', :body => 'body', :name => name, :profile => profile) | ||
5 | + track.add_category(fast_create(Category)) | ||
6 | + track.save! | ||
7 | + track | ||
8 | +end |
plugins/community_track/test/unit/community_track_plugin/step_test.rb
@@ -4,7 +4,11 @@ class StepTest < ActiveSupport::TestCase | @@ -4,7 +4,11 @@ class StepTest < ActiveSupport::TestCase | ||
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | @profile = fast_create(Community) | 6 | @profile = fast_create(Community) |
7 | - @track = CommunityTrackPlugin::Track.create(:profile_id => @profile.id, :name => 'track') | 7 | + @track = CommunityTrackPlugin::Track.new(:profile_id => @profile.id, :name => 'track') |
8 | + @category = fast_create(Category) | ||
9 | + @track.add_category(@category) | ||
10 | + @track.save! | ||
11 | + | ||
8 | @step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) | 12 | @step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) |
9 | Delayed::Job.destroy_all | 13 | Delayed::Job.destroy_all |
10 | end | 14 | end |
plugins/community_track/test/unit/community_track_plugin/track_list_block_test.rb
@@ -3,13 +3,14 @@ require File.dirname(__FILE__) + '/../../test_helper' | @@ -3,13 +3,14 @@ require File.dirname(__FILE__) + '/../../test_helper' | ||
3 | class TrackListBlockTest < ActiveSupport::TestCase | 3 | class TrackListBlockTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | - @community = fast_create(Community) | ||
7 | - @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @community) | ||
8 | - | ||
9 | - box = fast_create(Box, :owner_id => @community.id, :owner_type => @community.class.name) | 6 | + @profile = fast_create(Community) |
7 | + @track = create_track('track', profile) | ||
8 | + box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name) | ||
10 | @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box) | 9 | @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box) |
11 | end | 10 | end |
12 | 11 | ||
12 | + attr_reader :profile | ||
13 | + | ||
13 | should 'describe yourself' do | 14 | should 'describe yourself' do |
14 | assert CommunityTrackPlugin::TrackListBlock.description | 15 | assert CommunityTrackPlugin::TrackListBlock.description |
15 | end | 16 | end |
@@ -23,38 +24,30 @@ class TrackListBlockTest < ActiveSupport::TestCase | @@ -23,38 +24,30 @@ class TrackListBlockTest < ActiveSupport::TestCase | ||
23 | end | 24 | end |
24 | 25 | ||
25 | should 'list articles only of track type' do | 26 | should 'list articles only of track type' do |
26 | - article = fast_create(Article, :profile_id => @community.id) | ||
27 | - assert_includes @community.articles, article | 27 | + article = fast_create(Article, :profile_id => profile.id) |
28 | + assert_includes profile.articles, article | ||
28 | assert_equal [@track], @block.tracks | 29 | assert_equal [@track], @block.tracks |
29 | end | 30 | end |
30 | 31 | ||
31 | should 'list of articles be limited by block configuration' do | 32 | should 'list of articles be limited by block configuration' do |
32 | - (@block.limit + 1).times do |i| | ||
33 | - track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community) | ||
34 | - end | 33 | + (@block.limit + 1).times { |i| create_track("track#{i}", profile) } |
35 | assert_equal @block.limit, @block.tracks.count | 34 | assert_equal @block.limit, @block.tracks.count |
36 | end | 35 | end |
37 | 36 | ||
38 | should 'return more link if has more tracks to show' do | 37 | should 'return more link if has more tracks to show' do |
39 | - @block.limit.times do |i| | ||
40 | - track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community) | ||
41 | - end | 38 | + @block.limit.times { |i| create_track("track#{i}", profile) } |
42 | assert @block.footer | 39 | assert @block.footer |
43 | end | 40 | end |
44 | 41 | ||
45 | should 'do not return more link if there is no more tracks to show' do | 42 | should 'do not return more link if there is no more tracks to show' do |
46 | - (@block.limit-1).times do |i| | ||
47 | - track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community) | ||
48 | - end | 43 | + (@block.limit-1).times { |i| create_track("track#{i}", profile) } |
49 | assert !@block.footer | 44 | assert !@block.footer |
50 | end | 45 | end |
51 | 46 | ||
52 | should 'count all tracks' do | 47 | should 'count all tracks' do |
53 | @block.owner.articles.destroy_all | 48 | @block.owner.articles.destroy_all |
54 | tracks_to_insert = @block.limit + 1 | 49 | tracks_to_insert = @block.limit + 1 |
55 | - tracks_to_insert.times do |i| | ||
56 | - track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community) | ||
57 | - end | 50 | + tracks_to_insert.times { |i| create_track("track#{i}", profile) } |
58 | article = fast_create(Article, :profile_id => @block.owner.id) | 51 | article = fast_create(Article, :profile_id => @block.owner.id) |
59 | @block.reload | 52 | @block.reload |
60 | assert_includes @block.owner.articles, article | 53 | assert_includes @block.owner.articles, article |
@@ -63,9 +56,7 @@ class TrackListBlockTest < ActiveSupport::TestCase | @@ -63,9 +56,7 @@ class TrackListBlockTest < ActiveSupport::TestCase | ||
63 | 56 | ||
64 | should 'have a second page if there is more tracks than limit' do | 57 | should 'have a second page if there is more tracks than limit' do |
65 | @block.owner.articles.destroy_all | 58 | @block.owner.articles.destroy_all |
66 | - (@block.limit+1).times do |i| | ||
67 | - track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => "track#{i}", :profile => @community) | ||
68 | - end | 59 | + (@block.limit+1).times { |i| create_track("track#{i}", profile) } |
69 | assert @block.has_page?(2) | 60 | assert @block.has_page?(2) |
70 | assert !@block.has_page?(3) | 61 | assert !@block.has_page?(3) |
71 | end | 62 | end |
@@ -74,9 +65,9 @@ class TrackListBlockTest < ActiveSupport::TestCase | @@ -74,9 +65,9 @@ class TrackListBlockTest < ActiveSupport::TestCase | ||
74 | @block.owner.articles.destroy_all | 65 | @block.owner.articles.destroy_all |
75 | category = fast_create(Category) | 66 | category = fast_create(Category) |
76 | category2 = fast_create(Category) | 67 | category2 = fast_create(Category) |
77 | - track1 = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track1', :profile => @community) | ||
78 | - track2 = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track2', :profile => @community) | ||
79 | - track3 = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track3', :profile => @community) | 68 | + track1 = create_track("track1", profile) |
69 | + track2 = create_track("track2", profile) | ||
70 | + track3 = create_track("track3", profile) | ||
80 | track1.add_category(category) | 71 | track1.add_category(category) |
81 | @block.category_ids = [category.id] | 72 | @block.category_ids = [category.id] |
82 | assert_equal [track1], @block.all_tracks | 73 | assert_equal [track1], @block.all_tracks |
@@ -85,8 +76,8 @@ class TrackListBlockTest < ActiveSupport::TestCase | @@ -85,8 +76,8 @@ class TrackListBlockTest < ActiveSupport::TestCase | ||
85 | should 'return all tracks if block does not filter by category' do | 76 | should 'return all tracks if block does not filter by category' do |
86 | @block.owner.articles.destroy_all | 77 | @block.owner.articles.destroy_all |
87 | category = fast_create(Category) | 78 | category = fast_create(Category) |
88 | - track1 = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track1', :profile => @community) | ||
89 | - track2 = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track2', :profile => @community) | 79 | + track1 = create_track("track1", profile) |
80 | + track2 = create_track("track2", profile) | ||
90 | track1.add_category(category) | 81 | track1.add_category(category) |
91 | assert_includes @block.all_tracks, track1 | 82 | assert_includes @block.all_tracks, track1 |
92 | assert_includes @block.all_tracks, track2 | 83 | assert_includes @block.all_tracks, track2 |
plugins/community_track/test/unit/community_track_plugin/track_test.rb
@@ -3,10 +3,10 @@ require File.dirname(__FILE__) + '/../../test_helper' | @@ -3,10 +3,10 @@ require File.dirname(__FILE__) + '/../../test_helper' | ||
3 | class TrackTest < ActiveSupport::TestCase | 3 | class TrackTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | - profile = fast_create(Community) | ||
7 | - @track = CommunityTrackPlugin::Track.create!(:profile => profile, :name => 'track') | ||
8 | - @step = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => 'step', :profile => profile) | ||
9 | - @tool = fast_create(Article, :parent_id => @step.id, :profile_id => profile.id) | 6 | + @profile = fast_create(Community) |
7 | + @track = create_track('track', @profile) | ||
8 | + @step = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => 'step', :profile => @profile) | ||
9 | + @tool = fast_create(Article, :parent_id => @step.id, :profile_id => @profile.id) | ||
10 | end | 10 | end |
11 | 11 | ||
12 | should 'describe yourself' do | 12 | should 'describe yourself' do |
@@ -43,6 +43,7 @@ class TrackTest < ActiveSupport::TestCase | @@ -43,6 +43,7 @@ class TrackTest < ActiveSupport::TestCase | ||
43 | top = fast_create(Category, :name => 'top category') | 43 | top = fast_create(Category, :name => 'top category') |
44 | category1 = fast_create(Category, :name => 'category1', :parent_id => top.id ) | 44 | category1 = fast_create(Category, :name => 'category1', :parent_id => top.id ) |
45 | category2 = fast_create(Category, :name => 'category2', :parent_id => category1.id ) | 45 | category2 = fast_create(Category, :name => 'category2', :parent_id => category1.id ) |
46 | + @track.categories.delete_all | ||
46 | @track.add_category(category2, true) | 47 | @track.add_category(category2, true) |
47 | assert_equal 'top category', @track.category_name | 48 | assert_equal 'top category', @track.category_name |
48 | end | 49 | end |
@@ -54,6 +55,7 @@ class TrackTest < ActiveSupport::TestCase | @@ -54,6 +55,7 @@ class TrackTest < ActiveSupport::TestCase | ||
54 | 55 | ||
55 | should 'return category name of first category' do | 56 | should 'return category name of first category' do |
56 | category = fast_create(Category, :name => 'category') | 57 | category = fast_create(Category, :name => 'category') |
58 | + @track.categories.delete_all | ||
57 | @track.add_category(category, true) | 59 | @track.add_category(category, true) |
58 | category2 = fast_create(Category, :name => 'category2') | 60 | category2 = fast_create(Category, :name => 'category2') |
59 | @track.add_category(category2, true) | 61 | @track.add_category(category2, true) |
@@ -126,4 +128,15 @@ class TrackTest < ActiveSupport::TestCase | @@ -126,4 +128,15 @@ class TrackTest < ActiveSupport::TestCase | ||
126 | assert_equal '', @track.first_paragraph | 128 | assert_equal '', @track.first_paragraph |
127 | end | 129 | end |
128 | 130 | ||
131 | + should 'not be able to create a track without category' do | ||
132 | + track = CommunityTrackPlugin::Track.create(:profile => @profile, :name => 'track') | ||
133 | + assert track.errors.invalid?(:categories) | ||
134 | + end | ||
135 | + | ||
136 | + should 'not be able to save a track without category' do | ||
137 | + @track.categories.delete_all | ||
138 | + @track.save | ||
139 | + assert @track.errors.invalid?(:categories) | ||
140 | + end | ||
141 | + | ||
129 | end | 142 | end |