Skip to content

Commit

Permalink
test added: tag
Browse files Browse the repository at this point in the history
  • Loading branch information
angdev committed Oct 30, 2014
1 parent 4d3e937 commit b74bf8b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 2 additions & 3 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ class Tag < ActiveRecord::Base
has_many :taggings
has_many :users, through: :taggings, source: :user

scope :fetch_list_by_tag_name, -> (tag_name){
scope :fetch_list_by_tag_name, -> (tag_name) {
tag_arel = Tag.arel_table
where(tag_arel[:tag_name].matches("%#{tag_name}%"))
}

end
end
11 changes: 11 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@

config.include ShowMeTheCookies, :type => :feature

config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end

config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
Expand Down
14 changes: 14 additions & 0 deletions spec/unit/models/tag_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require "rails_helper"

RSpec.describe Tag, :type => :model do
describe "#fetch_list_by_tag_name" do
it "should fetch tag list where like name" do
tag1 = Tag.create!(tag_name: "Hello")
tag2 = Tag.create!(tag_name: "World")
tag3 = Tag.create!(tag_name: "Yellow")

expect(Tag.fetch_list_by_tag_name("Worl")).to contain_exactly(tag2)
expect(Tag.fetch_list_by_tag_name("llo")).to contain_exactly(tag1, tag3)
end
end
end

0 comments on commit b74bf8b

Please sign in to comment.