Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request mbleigh#740 from pcupueran/add_rspecs_to_tagging_spec
Browse files Browse the repository at this point in the history
Add rspecs to tagging spec
  • Loading branch information
seuros committed Mar 2, 2016
2 parents f88182d + 75dc433 commit 67764da
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
74 changes: 64 additions & 10 deletions spec/acts_as_taggable_on/tagging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 67764da

Please sign in to comment.