Skip to content

Commit 55a242d

Browse files
committed
test added: tag
1 parent 4d3e937 commit 55a242d

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

app/models/tag.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ class Tag < ActiveRecord::Base
22
has_many :taggings
33
has_many :users, through: :taggings, source: :user
44

5-
scope :fetch_list_by_tag_name, -> (tag_name){
5+
scope :fetch_list_by_tag_name, -> (tag_name) {
66
tag_arel = Tag.arel_table
77
where(tag_arel[:tag_name].matches("%#{tag_name}%"))
88
}
9-
10-
end
9+
end

app/models/user.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ class User < ActiveRecord::Base
1515
scope "responsed_#{status}", -> (notice) { responsed_to_notice(notice).merge(Response.where(status: status)) }
1616
end
1717
scope :responsed_not_to_notice, -> (notice) {
18-
SQL = %{LEFT OUTER JOIN (SELECT * FROM responses WHERE responses.notice_id = #{notice.id} ) A
18+
sql = %{LEFT OUTER JOIN (SELECT * FROM responses WHERE responses.notice_id = #{notice.id} ) A
1919
ON users.id = A.user_id
2020
WHERE A.status is null}
21-
joins(SQL) }
21+
joins(sql) }
2222

2323
scope :order_by_responsed_at, -> {order('responses.created_at ASC')}
2424
scope :order_by_read_at, -> {order('read_activity_marks.created_at DESC')}

spec/rails_helper.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@
3030

3131
config.include ShowMeTheCookies, :type => :feature
3232

33+
config.before(:suite) do
34+
DatabaseCleaner.strategy = :transaction
35+
DatabaseCleaner.clean_with(:truncation)
36+
end
37+
38+
config.around(:each) do |example|
39+
DatabaseCleaner.cleaning do
40+
example.run
41+
end
42+
end
43+
3344
# If you're not using ActiveRecord, or you'd prefer not to run each of your
3445
# examples within a transaction, remove the following line or assign false
3546
# instead of true.

spec/unit/models/tag_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require "rails_helper"
2+
3+
RSpec.describe Tag, :type => :model do
4+
describe "#fetch_list_by_tag_name" do
5+
it "should fetch tag list where like name" do
6+
tag1 = Tag.create!(tag_name: "Hello")
7+
tag2 = Tag.create!(tag_name: "World")
8+
tag3 = Tag.create!(tag_name: "Yellow")
9+
10+
expect(Tag.fetch_list_by_tag_name("Worl")).to contain_exactly(tag2)
11+
expect(Tag.fetch_list_by_tag_name("llo")).to contain_exactly(tag1, tag3)
12+
end
13+
end
14+
end

0 commit comments

Comments
 (0)