Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rspecs to tagging spec #740

Merged
merged 2 commits into from
Mar 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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