Commit 9b6bcaf76dccaa72ed59be8fb465a575a5a9bc27
1 parent
9e8fd78e
Exists in
master
and in
27 other branches
community_track: fix tests
Showing
1 changed file
with
16 additions
and
13 deletions
Show diff stats
plugins/community_track/test/unit/community_track_plugin_test.rb
| @@ -6,10 +6,13 @@ class CommunityTrackPluginTest < ActiveSupport::TestCase | @@ -6,10 +6,13 @@ class CommunityTrackPluginTest < ActiveSupport::TestCase | ||
| 6 | @plugin = CommunityTrackPlugin.new | 6 | @plugin = CommunityTrackPlugin.new |
| 7 | @profile = fast_create(Community) | 7 | @profile = fast_create(Community) |
| 8 | @params = {} | 8 | @params = {} |
| 9 | - @plugin.stubs(:context).returns(self) | 9 | + @context = mock |
| 10 | + @context.stubs(:profile).returns(@profile) | ||
| 11 | + @context.stubs(:params).returns(@params) | ||
| 12 | + @plugin.stubs(:context).returns(@context) | ||
| 10 | end | 13 | end |
| 11 | 14 | ||
| 12 | - attr_reader :profile, :params | 15 | + attr_reader :profile, :params, :context |
| 13 | 16 | ||
| 14 | should 'has name' do | 17 | should 'has name' do |
| 15 | assert CommunityTrackPlugin.plugin_name | 18 | assert CommunityTrackPlugin.plugin_name |
| @@ -28,37 +31,37 @@ class CommunityTrackPluginTest < ActiveSupport::TestCase | @@ -28,37 +31,37 @@ class CommunityTrackPluginTest < ActiveSupport::TestCase | ||
| 28 | end | 31 | end |
| 29 | 32 | ||
| 30 | should 'do not return Track as a content type if profile is not a community' do | 33 | should 'do not return Track as a content type if profile is not a community' do |
| 31 | - @profile = Organization.new | 34 | + context.stubs(:profile).returns(Organization.new) |
| 32 | assert_not_includes @plugin.content_types, CommunityTrackPlugin::Track | 35 | assert_not_includes @plugin.content_types, CommunityTrackPlugin::Track |
| 33 | end | 36 | end |
| 34 | 37 | ||
| 35 | should 'do not return Track as a content type if there is a parent' do | 38 | should 'do not return Track as a content type if there is a parent' do |
| 36 | - parent = fast_create(Blog, :profile_id => @profile.id) | ||
| 37 | - @params[:parent_id] = parent.id | 39 | + parent = fast_create(Blog, :profile_id => profile.id) |
| 40 | + params[:parent_id] = parent.id | ||
| 38 | assert_not_includes @plugin.content_types, CommunityTrackPlugin::Track | 41 | assert_not_includes @plugin.content_types, CommunityTrackPlugin::Track |
| 39 | end | 42 | end |
| 40 | 43 | ||
| 41 | should 'return Step as a content type if parent is a Track' do | 44 | should 'return Step as a content type if parent is a Track' do |
| 42 | - parent = fast_create(CommunityTrackPlugin::Track, :profile_id => @profile.id) | ||
| 43 | - @params[:parent_id] = parent.id | 45 | + parent = fast_create(CommunityTrackPlugin::Track, :profile_id => profile.id) |
| 46 | + params[:parent_id] = parent.id | ||
| 44 | assert_includes @plugin.content_types, CommunityTrackPlugin::Step | 47 | assert_includes @plugin.content_types, CommunityTrackPlugin::Step |
| 45 | end | 48 | end |
| 46 | 49 | ||
| 47 | should 'do not return Step as a content type if parent is not a Track' do | 50 | should 'do not return Step as a content type if parent is not a Track' do |
| 48 | - parent = fast_create(Blog, :profile_id => @profile.id) | ||
| 49 | - @params[:parent_id] = parent.id | 51 | + parent = fast_create(Blog, :profile_id => profile.id) |
| 52 | + params[:parent_id] = parent.id | ||
| 50 | assert_not_includes @plugin.content_types, CommunityTrackPlugin::Step | 53 | assert_not_includes @plugin.content_types, CommunityTrackPlugin::Step |
| 51 | end | 54 | end |
| 52 | 55 | ||
| 53 | should 'return Track and Step as a content type if context has no params' do | 56 | should 'return Track and Step as a content type if context has no params' do |
| 54 | - parent = fast_create(Blog, :profile_id => @profile.id) | ||
| 55 | - expects(:respond_to?).with(:params).returns(false) | 57 | + parent = fast_create(Blog, :profile_id => profile.id) |
| 58 | + context.expects(:respond_to?).with(:params).returns(false) | ||
| 56 | assert_equivalent [CommunityTrackPlugin::Step, CommunityTrackPlugin::Track], @plugin.content_types | 59 | assert_equivalent [CommunityTrackPlugin::Step, CommunityTrackPlugin::Track], @plugin.content_types |
| 57 | end | 60 | end |
| 58 | 61 | ||
| 59 | should 'return Track and Step as a content type if params is nil' do | 62 | should 'return Track and Step as a content type if params is nil' do |
| 60 | - parent = fast_create(Blog, :profile_id => @profile.id) | ||
| 61 | - @params = nil | 63 | + parent = fast_create(Blog, :profile_id => profile.id) |
| 64 | + context.stubs(:params).returns(nil) | ||
| 62 | assert_equivalent [CommunityTrackPlugin::Step, CommunityTrackPlugin::Track], @plugin.content_types | 65 | assert_equivalent [CommunityTrackPlugin::Step, CommunityTrackPlugin::Track], @plugin.content_types |
| 63 | end | 66 | end |
| 64 | 67 |