~mrls/activerecord-except

ref: 7a5541a4540035581a0a30f50d62d22987de03af activerecord-except/test/activerecord/except_test.rb -rw-r--r-- 914 bytes
7a5541a4Mauro Morales Initial commit 1 year, 26 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# frozen_string_literal: true

require 'active_record'
require 'test_helper'

class User < ActiveRecord::Base
end

class ExceptTest < Minitest::Test
  def setup
    ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')

    ActiveRecord::Schema.define do
      create_table :users do |t|
        t.string :first_name
        t.string :last_name
        t.string :address
        t.string :file
      end
    end

    User.create!(first_name: 'Max',
                 last_name: 'Musterman',
                 address: 'Berlin',
                 file: 'avatar.jpg')
  end

  def test_except
    user = User.where(address: 'Berlin').except(:file).first

    # implied assertion that no exceptions are raised
    assert_equal user.first_name, 'Max'
    assert_equal user.last_name, 'Musterman'
    assert_equal user.address, 'Berlin'
    assert_raises(NoMethodError) { user.file }
  end
end