Skip to content

Commit

Permalink
Merge pull request #17 from pocke/Add_test_for__IS_NULL__and__IS_NOT_…
Browse files Browse the repository at this point in the history
…NULL_

Add test for `IS NULL` and `IS NOT NULL`
  • Loading branch information
pocke committed Mar 16, 2024
2 parents 3509e09 + 48e9f54 commit b417753
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion spec/activerecord/originator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
end

it 'annotates != operator' do
expect(Post.not_eq.to_sql).to eq(<<~SQL)
expect(Post.not_eq('hello').to_sql).to eq(<<~SQL)
SELECT "posts".* FROM "posts" WHERE "posts"."title" != 'hello' /* /spec/support/post.rb:9 */
SQL
end
Expand Down Expand Up @@ -51,6 +51,18 @@
SELECT "posts".* FROM "posts" WHERE "posts"."id" < 42 /* /spec/support/post.rb:8 */
SQL
end

it 'annotates IS NULL operator' do
expect(Post.state_for(nil).to_sql).to eq(<<~SQL)
SELECT "posts".* FROM "posts" WHERE "posts"."state" IS NULL /* /spec/support/post.rb:6 */
SQL
end

it 'annotates IS NOT NULL operator' do
expect(Post.not_eq(nil).to_sql).to eq(<<~SQL)
SELECT "posts".* FROM "posts" WHERE "posts"."title" IS NOT NULL /* /spec/support/post.rb:9 */
SQL
end
end

it 'annotates a ORDER BY asc clause' do
Expand Down
2 changes: 1 addition & 1 deletion spec/support/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class Post < ActiveRecord::Base
scope :state_for, ->(state) { where(state: state) }
scope :not_state_for, ->(state) { where.not(state: state) }
scope :compare_id, ->(range) { where(id: range) }
scope :not_eq, -> { where.not(title: 'hello') }
scope :not_eq, ->(title) { where.not(title: title) }
scope :order_by_title, ->(direction) { order(title: direction) }
end

0 comments on commit b417753

Please sign in to comment.