From 3749a0d6f45ed85b0182f67b865827a08a1071ad Mon Sep 17 00:00:00 2001 From: Patricia Date: Wed, 17 Feb 2016 16:31:38 +0000 Subject: [PATCH 1/2] Add rspec tests for context scopes for tagging_spec Add rspec for owned_by scope Add rspec for owned_by scope a tagging should belong to a specific user Add rspec test for owned by scope a tagging should belong to a specific user Add rspec test for by_context tagging scope a tagging should be found by context Add rspec test for by_contexts tagging scope taggings can be found by contexts Add rspec test for not_owned tagging scope not_owned scope should found the taggings that do not have owner Refactor owned_by rspec test for tagging_rspec Refactor by_contexts rspec test for tagging_rspec --- spec/acts_as_taggable_on/tagging_spec.rb | 74 ++++++++++++++++++++---- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/spec/acts_as_taggable_on/tagging_spec.rb b/spec/acts_as_taggable_on/tagging_spec.rb index 9586e9a5e..7c3290a45 100644 --- a/spec/acts_as_taggable_on/tagging_spec.rb +++ b/spec/acts_as_taggable_on/tagging_spec.rb @@ -49,15 +49,69 @@ ActsAsTaggableOn.remove_unused_tags = previous_setting end - pending 'context scopes' do - describe '.by_context' - - describe '.by_contexts' - - describe '.owned_by' - - describe '.not_owned' - + describe 'context scopes' do + before do + @tagging_2 = ActsAsTaggableOn::Tagging.new + @tagging_3 = ActsAsTaggableOn::Tagging.new + + @tagger = User.new + @tagger_2 = User.new + + @tagging.taggable = TaggableModel.create(name: "Black holes") + @tagging.tag = ActsAsTaggableOn::Tag.create(name: "Physics") + @tagging.tagger = @tagger + @tagging.context = 'Science' + @tagging.save + + @tagging_2.taggable = TaggableModel.create(name: "Satellites") + @tagging_2.tag = ActsAsTaggableOn::Tag.create(name: "Technology") + @tagging_2.tagger = @tagger_2 + @tagging_2.context = 'Science' + @tagging_2.save + + @tagging_3.taggable = TaggableModel.create(name: "Satellites") + @tagging_3.tag = ActsAsTaggableOn::Tag.create(name: "Engineering") + @tagging_3.tagger = @tagger_2 + @tagging_3.context = 'Astronomy' + @tagging_3.save + + end + + describe '.owned_by' do + it "should belong to a specific user" do + expect(ActsAsTaggableOn::Tagging.owned_by(@tagger).first).to eq(@tagging) + end + end + + describe '.by_context' do + it "should be found by context" do + expect(ActsAsTaggableOn::Tagging.by_context('Science').length).to eq(2); + end + end + + describe '.by_contexts' do + it "should find taggings by contexts" do + expect(ActsAsTaggableOn::Tagging.by_contexts(['Science', 'Astronomy']).first).to eq(@tagging); + expect(ActsAsTaggableOn::Tagging.by_contexts(['Science', 'Astronomy']).second).to eq(@tagging_2); + expect(ActsAsTaggableOn::Tagging.by_contexts(['Science', 'Astronomy']).third).to eq(@tagging_3); + expect(ActsAsTaggableOn::Tagging.by_contexts(['Science', 'Astronomy']).length).to eq(3); + end + end + + describe '.not_owned' do + before do + @tagging_4 = ActsAsTaggableOn::Tagging.new + @tagging_4.taggable = TaggableModel.create(name: "Gravity") + @tagging_4.tag = ActsAsTaggableOn::Tag.create(name: "Space") + @tagging_4.context = "Science" + @tagging_4.save + end + + it "should found the taggings that do not have owner" do + expect(ActsAsTaggableOn::Tagging.all.length).to eq(4) + expect(ActsAsTaggableOn::Tagging.not_owned.length).to eq(1) + expect(ActsAsTaggableOn::Tagging.not_owned.first).to eq(@tagging_4) + end + end end - end From 75dc433e23b07bd8d24300b1550060bd29619c51 Mon Sep 17 00:00:00 2001 From: Patricia Date: Thu, 18 Feb 2016 10:57:48 +0000 Subject: [PATCH 2/2] Update changelog Update changelog Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48e67f101..5928d33b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ As such, a _Feature_ would map to either major or minor. A _bug fix_ to a patch. * Fixes * [@rikettsie Fixed collation for MySql via rake rule or config parameter](https://github.com/mbleigh/acts-as-taggable-on/pull/634) + *Misc + * [@pcupueran Add rspec test for tagging_spec completeness]() ### [3.4.4 / 2015-02-11](https://github.com/mbleigh/acts-as-taggable-on/compare/v3.4.3...v3.4.4)