Commit e137c34df22d1463574a2af3f197c81fd5181a6f

Authored by Rodrigo Souto
1 parent aae9aa42

community-track-plugin: fix tests by creating a profile with default boxes

plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb
@@ -10,7 +10,7 @@ end @@ -10,7 +10,7 @@ end
10 class ContentViewerControllerTest < ActionController::TestCase 10 class ContentViewerControllerTest < ActionController::TestCase
11 11
12 def setup 12 def setup
13 - @profile = fast_create(Community) 13 + @profile = Community.create!(:name => 'Sample community', :identifier => 'sample-community')
14 @track = create_track('track', @profile) 14 @track = create_track('track', @profile)
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) 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)
16 16
@@ -87,43 +87,35 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -87,43 +87,35 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
87 end 87 end
88 88
89 should 'render a div with block id for track list block' do 89 should 'render a div with block id for track list block' do
90 - box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name)  
91 - @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box)  
92 - @profile.boxes << box 90 + @block = CommunityTrackPlugin::TrackListBlock.create!(:box => @profile.boxes.last)
93 get :view_page, @step.url 91 get :view_page, @step.url
94 assert_tag :tag => 'div', :attributes => { :class => 'track_list', :id => "track_list_#{@block.id}" } 92 assert_tag :tag => 'div', :attributes => { :class => 'track_list', :id => "track_list_#{@block.id}" }
95 end 93 end
96 94
97 should 'render a div with block id for track card list block' do 95 should 'render a div with block id for track card list block' do
98 - box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name)  
99 - @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box)  
100 - @profile.boxes << box 96 + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => @profile.boxes.last)
101 get :view_page, @step.url 97 get :view_page, @step.url
102 assert_tag :tag => 'div', :attributes => { :class => 'track_list', :id => "track_list_#{@block.id}" } 98 assert_tag :tag => 'div', :attributes => { :class => 'track_list', :id => "track_list_#{@block.id}" }
103 end 99 end
104 100
105 should 'render tracks in track list block' do 101 should 'render tracks in track list block' do
106 - box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name)  
107 - @block = CommunityTrackPlugin::TrackListBlock.create!(:box => box)  
108 - @profile.boxes << box 102 + @block = CommunityTrackPlugin::TrackListBlock.create!(:box => @profile.boxes.last)
109 get :view_page, @step.url 103 get :view_page, @step.url
  104 + file = File.open('result.html', 'w+')
  105 + file.write(@response.body)
  106 + file.close
110 assert_tag :tag => 'div', :attributes => { :class => "item category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'steps' }, :descendant => { :tag => 'span', :attributes => { :class => "step #{@block.status_class(@step)}" } } } 107 assert_tag :tag => 'div', :attributes => { :class => "item category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'steps' }, :descendant => { :tag => 'span', :attributes => { :class => "step #{@block.status_class(@step)}" } } }
111 end 108 end
112 109
113 should 'render tracks in track card list block' do 110 should 'render tracks in track card list block' do
114 - box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name)  
115 - @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box)  
116 - @profile.boxes << box 111 + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => @profile.boxes.last)
117 get :view_page, @step.url 112 get :view_page, @step.url
118 assert_tag :tag => 'div', :attributes => { :class => "item_card category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'track_content' } } 113 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' } } 114 assert_tag :tag => 'div', :attributes => { :class => "item_card category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'track_stats' } }
120 end 115 end
121 116
122 should 'render link to display more tracks in track list block' do 117 should 'render link to display more tracks in track list block' do
123 - box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name)  
124 - @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box)  
125 - @profile.boxes << box  
126 - 118 + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => @profile.boxes.last)
127 (@block.limit+1).times { |i| create_track("track#{i}", @profile) } 119 (@block.limit+1).times { |i| create_track("track#{i}", @profile) }
128 120
129 get :view_page, @step.url 121 get :view_page, @step.url
@@ -131,9 +123,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -131,9 +123,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
131 end 123 end
132 124
133 should 'render link to show all tracks in track list block' do 125 should 'render link to show all tracks in track list block' do
134 - box = fast_create(Box, :owner_id => @profile.id, :owner_type => @profile.class.name)  
135 - @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => box)  
136 - @profile.boxes << box 126 + @block = CommunityTrackPlugin::TrackCardListBlock.create!(:box => @profile.boxes.last)
137 @block.more_another_page = true 127 @block.more_another_page = true
138 @block.save! 128 @block.save!
139 129