remockable 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +2 -3
  5. data/CHANGELOG.md +6 -0
  6. data/README.markdown +18 -4
  7. data/lib/remockable/active_model/allow_values_for.rb +14 -13
  8. data/lib/remockable/active_model/helpers.rb +7 -6
  9. data/lib/remockable/active_model/validate_acceptance_of.rb +9 -11
  10. data/lib/remockable/active_model/validate_confirmation_of.rb +9 -11
  11. data/lib/remockable/active_model/validate_exclusion_of.rb +9 -11
  12. data/lib/remockable/active_model/validate_format_of.rb +9 -11
  13. data/lib/remockable/active_model/validate_inclusion_of.rb +9 -11
  14. data/lib/remockable/active_model/validate_length_of.rb +32 -19
  15. data/lib/remockable/active_model/validate_numericality_of.rb +23 -12
  16. data/lib/remockable/active_model/validate_presence_of.rb +9 -11
  17. data/lib/remockable/active_record/accept_nested_attributes_for.rb +10 -13
  18. data/lib/remockable/active_record/belong_to.rb +21 -13
  19. data/lib/remockable/active_record/have_and_belong_to_many.rb +16 -13
  20. data/lib/remockable/active_record/have_column.rb +14 -11
  21. data/lib/remockable/active_record/have_default_scope.rb +38 -20
  22. data/lib/remockable/active_record/have_index.rb +12 -13
  23. data/lib/remockable/active_record/have_many.rb +22 -13
  24. data/lib/remockable/active_record/have_one.rb +21 -13
  25. data/lib/remockable/active_record/have_scope.rb +40 -25
  26. data/lib/remockable/active_record/helpers.rb +3 -0
  27. data/lib/remockable/active_record/validate_associated.rb +9 -11
  28. data/lib/remockable/active_record/validate_uniqueness_of.rb +19 -11
  29. data/lib/remockable/helpers.rb +58 -6
  30. data/lib/remockable/version.rb +1 -1
  31. data/remockable.gemspec +3 -3
  32. data/spec/active_model/allow_values_for_spec.rb +19 -13
  33. data/spec/active_model/validate_acceptance_of_spec.rb +0 -2
  34. data/spec/active_model/validate_confirmation_of_spec.rb +0 -2
  35. data/spec/active_model/validate_exclusion_of_spec.rb +7 -9
  36. data/spec/active_model/validate_format_of_spec.rb +9 -11
  37. data/spec/active_model/validate_inclusion_of_spec.rb +7 -9
  38. data/spec/active_model/validate_length_of_spec.rb +16 -18
  39. data/spec/active_model/validate_numericality_of_spec.rb +14 -16
  40. data/spec/active_model/validate_presence_of_spec.rb +0 -2
  41. data/spec/active_record/accept_nested_attributes_for_spec.rb +22 -18
  42. data/spec/active_record/belong_to_spec.rb +26 -26
  43. data/spec/active_record/have_and_belong_to_many_spec.rb +22 -20
  44. data/spec/active_record/have_column_spec.rb +32 -35
  45. data/spec/active_record/have_default_scope_spec.rb +54 -55
  46. data/spec/active_record/have_index_spec.rb +24 -27
  47. data/spec/active_record/have_many_spec.rb +10 -11
  48. data/spec/active_record/have_one_spec.rb +26 -25
  49. data/spec/active_record/have_scope_spec.rb +75 -75
  50. data/spec/active_record/validate_associated_spec.rb +11 -11
  51. data/spec/active_record/validate_uniqueness_of_spec.rb +11 -13
  52. data/spec/spec_helper.rb +2 -4
  53. data/spec/support/active_record_example_group.rb +3 -4
  54. data/spec/support/class_builder.rb +15 -11
  55. data/spec/support/shared/a_validation_matcher.rb +25 -25
  56. data/spec/support/shared/an_active_record_matcher.rb +14 -12
  57. metadata +60 -84
@@ -1,38 +1,44 @@
1
- require 'spec_helper'
2
-
3
1
  describe :allow_values_for do
4
2
  let(:attribute) { :one }
5
3
  let(:values) { ['123'] }
6
4
  let(:matcher_name) { self.class.parent.description }
7
5
 
8
- let(:model) do
9
- build_class(:User) { include ActiveModel::Validations }
10
- end
6
+ let(:model) {
7
+ build_class :User do
8
+ include ActiveModel::Validations
9
+ end
10
+ }
11
11
 
12
- before { model.validates(attribute, :format => /\A\d+\Z/) }
12
+ subject(:instance) { model.new }
13
13
 
14
- subject { model.new }
14
+ before do
15
+ model.validates attribute, format: /\A\d+\Z/
16
+ end
15
17
 
16
18
  context 'description' do
17
19
  it 'has a custom description' do
18
20
  matcher = allow_values_for(attribute, *values)
19
- matcher.description.should == "allow the values #{values.collect(&:inspect).to_sentence} for #{attribute}"
21
+
22
+ expect(matcher.description)
23
+ .to eq "allow the values #{values.collect(&:inspect).to_sentence} for #{attribute}"
20
24
  end
21
25
  end
22
26
 
23
27
  context 'failure messages' do
24
28
  let(:matcher) { allow_values_for(attribute, *values) }
25
29
 
26
- before { matcher.matches?(subject) }
30
+ before do
31
+ matcher.matches? instance
32
+ end
27
33
 
28
34
  it 'has a custom failure message' do
29
- matcher.failure_message_for_should.should ==
30
- "Expected #{subject.class.name} to #{matcher.description}"
35
+ expect(matcher.failure_message)
36
+ .to eq "Expected #{instance.class.name} to #{matcher.description}"
31
37
  end
32
38
 
33
39
  it 'has a custom negative failure message' do
34
- matcher.failure_message_for_should_not.should ==
35
- "Did not expect #{subject.class.name} to #{matcher.description}"
40
+ expect(matcher.failure_message_when_negated)
41
+ .to eq "Did not expect #{instance.class.name} to #{matcher.description}"
36
42
  end
37
43
  end
38
44
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe :validate_acceptance_of do
4
2
  let(:validator_name) { :acceptance }
5
3
  let(:default_options) { true }
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe :validate_confirmation_of do
4
2
  let(:validator_name) { :confirmation }
5
3
  let(:default_options) { true }
@@ -1,16 +1,14 @@
1
- require 'spec_helper'
2
-
3
1
  describe :validate_exclusion_of do
4
2
  let(:validator_name) { :exclusion }
5
- let(:default_options) { { :in => [true, false] } }
3
+ let(:default_options) { { in: [true, false] } }
6
4
 
7
5
  it_behaves_like 'a validation matcher' do
8
- with_option(:allow_blank, true, false)
9
- with_option(:allow_nil, true, false)
10
- with_option(:in, [true, false], %w(male female))
11
- with_option(:message, 'is in list!', 'invalid')
6
+ with_option :allow_blank, true, false
7
+ with_option :allow_nil, true, false
8
+ with_option :in, [true, false], %w(male female)
9
+ with_option :message, 'is in list!', 'invalid'
12
10
 
13
- with_conditional_option(:if)
14
- with_conditional_option(:unless)
11
+ with_conditional_option :if
12
+ with_conditional_option :unless
15
13
  end
16
14
  end
@@ -1,18 +1,16 @@
1
- require 'spec_helper'
2
-
3
1
  describe :validate_format_of do
4
2
  let(:validator_name) { :format }
5
- let(:default_options) { { :with => /\d+/ } }
3
+ let(:default_options) { { with: /\d+/ } }
6
4
 
7
5
  it_behaves_like 'a validation matcher' do
8
- with_option(:allow_blank, true, false)
9
- with_option(:allow_nil, true, false)
10
- with_option(:message, 'is the wrong format!', 'invalid')
11
- with_option(:on, :create, :update)
12
- with_option!(:with, /\d+/, /\w+/)
13
- with_option!(:without, /\d+/, /\w+/)
6
+ with_option :allow_blank, true, false
7
+ with_option :allow_nil, true, false
8
+ with_option :message, 'is the wrong format!', 'invalid'
9
+ with_option :on, :create, :update
10
+ with_option! :with, /\d+/, /\w+/
11
+ with_option! :without, /\d+/, /\w+/
14
12
 
15
- with_conditional_option(:if)
16
- with_conditional_option(:unless)
13
+ with_conditional_option :if
14
+ with_conditional_option :unless
17
15
  end
18
16
  end
@@ -1,16 +1,14 @@
1
- require 'spec_helper'
2
-
3
1
  describe :validate_inclusion_of do
4
2
  let(:validator_name) { :inclusion }
5
- let(:default_options) { { :in => [true, false] } }
3
+ let(:default_options) { { in: [true, false] } }
6
4
 
7
5
  it_behaves_like 'a validation matcher' do
8
- with_option(:allow_blank, true, false)
9
- with_option(:allow_nil, true, false)
10
- with_option(:in, [true, false], %w(male female))
11
- with_option(:message, 'is not in list!', 'invalid')
6
+ with_option :allow_blank, true, false
7
+ with_option :allow_nil, true, false
8
+ with_option :in, [true, false], %w(male female)
9
+ with_option :message, 'is not in list!', 'invalid'
12
10
 
13
- with_conditional_option(:if)
14
- with_conditional_option(:unless)
11
+ with_conditional_option :if
12
+ with_conditional_option :unless
15
13
  end
16
14
  end
@@ -1,26 +1,24 @@
1
- require 'spec_helper'
2
-
3
1
  describe :validate_length_of do
4
2
  let(:validator_name) { :length }
5
- let(:default_options) { { :is => 5 } }
3
+ let(:default_options) { { is: 5 } }
6
4
 
7
5
  it_behaves_like 'a validation matcher' do
8
- with_option(:allow_blank, true, false)
9
- with_option(:allow_nil, true, false)
10
- with_option(:in, 1..10, 1..5)
11
- with_option(:is, 5, 10)
12
- with_option(:maximum, 5, 10)
13
- with_option(:message, 'is the wrong length!', 'invalid')
14
- with_option(:minimum, 5, 10)
15
- with_option(:on, :create, :update)
16
- with_option(:too_long, 'is too long!', 'invalid')
17
- with_option(:too_short, 'is too short!', 'invalid')
18
- with_option(:within, 1..10, 1..5)
19
- with_option(:wrong_length, 'is not five!', 'invalid')
6
+ with_option :allow_blank, true, false
7
+ with_option :allow_nil, true, false
8
+ with_option :in, 1..10, 1..5
9
+ with_option :is, 5, 10
10
+ with_option :maximum, 5, 10
11
+ with_option :message, 'is the wrong length!', 'invalid'
12
+ with_option :minimum, 5, 10
13
+ with_option :on, :create, :update
14
+ with_option :too_long, 'is too long!', 'invalid'
15
+ with_option :too_short, 'is too short!', 'invalid'
16
+ with_option :within, 1..10, 1..5
17
+ with_option :wrong_length, 'is not five!', 'invalid'
20
18
 
21
- with_conditional_option(:if)
22
- with_conditional_option(:unless)
19
+ with_conditional_option :if
20
+ with_conditional_option :unless
23
21
 
24
- with_unsupported_option(:tokenizer, lambda { |string| string.scan(/\w+/) })
22
+ with_unsupported_option :tokenizer, ->(string) { string.scan(/\w+/) }
25
23
  end
26
24
  end
@@ -1,23 +1,21 @@
1
- require 'spec_helper'
2
-
3
1
  describe :validate_numericality_of do
4
2
  let(:validator_name) { :numericality }
5
- let(:default_options) { { :only_integer => true } }
3
+ let(:default_options) { { only_integer: true } }
6
4
 
7
5
  it_behaves_like 'a validation matcher' do
8
- with_option(:allow_nil, true, false)
9
- with_option(:equal_to, 5, 10)
10
- with_option(:even, true, false)
11
- with_option(:greater_than, 5, 10)
12
- with_option(:greater_than_or_equal_to, 5, 10)
13
- with_option(:less_than, 5, 10)
14
- with_option(:less_than_or_equal_to, 5, 10)
15
- with_option(:message, 'is the wrong numericality!', 'invalid')
16
- with_option(:odd, true, false)
17
- with_option(:on, :create, :update)
18
- with_option(:only_integer, true, false)
6
+ with_option :allow_nil, true, false
7
+ with_option :equal_to, 5, 10
8
+ with_option :even, true, false
9
+ with_option :greater_than, 5, 10
10
+ with_option :greater_than_or_equal_to, 5, 10
11
+ with_option :less_than, 5, 10
12
+ with_option :less_than_or_equal_to, 5, 10
13
+ with_option :message, 'is the wrong numericality!', 'invalid'
14
+ with_option :odd, true, false
15
+ with_option :on, :create, :update
16
+ with_option :only_integer, true, false
19
17
 
20
- with_conditional_option(:if)
21
- with_conditional_option(:unless)
18
+ with_conditional_option :if
19
+ with_conditional_option :unless
22
20
  end
23
21
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe :validate_presence_of do
4
2
  let(:validator_name) { :presence }
5
3
  let(:default_options) { true }
@@ -1,27 +1,31 @@
1
- require 'spec_helper'
2
-
3
1
  describe :accept_nested_attributes_for do
4
2
  let(:macro) { :accepts_nested_attributes_for }
5
- let(:options) { [:company, { :allow_destroy => true }] }
3
+ let(:options) { [:company, { allow_destroy: true }] }
6
4
 
7
5
  it_behaves_like 'an Active Record matcher' do
8
6
  let(:matcher_name) { :accept_nested_attributes_for }
9
7
 
10
- let(:model) do
11
- build_class(:User, ActiveRecord::Base) { belongs_to :company }
12
- end
8
+ let(:model) {
9
+ build_class :User, ActiveRecord::Base do
10
+ belongs_to :company
11
+ end
12
+ }
13
13
 
14
- before { create_table(:users) }
14
+ subject(:instance) { model.new }
15
15
 
16
- subject { model.new }
16
+ before do
17
+ create_table :users
18
+ end
17
19
 
18
20
  context 'description' do
19
21
  let(:matcher) { send(matcher_name, *options) }
20
22
 
21
23
  it 'has a custom description' do
22
- association = matcher.instance_variable_get(:@association)
23
- with = " with #{matcher.expected.inspect}" if matcher.expected.any?
24
- matcher.description.should == "accept nested attributes for #{association}#{with}"
24
+ association = matcher.attribute
25
+ with = " with #{matcher.options.inspect}" if matcher.options.any?
26
+
27
+ expect(matcher.description)
28
+ .to eq "accept nested attributes for #{association}#{with}"
25
29
  end
26
30
  end
27
31
 
@@ -29,19 +33,19 @@ describe :accept_nested_attributes_for do
29
33
  let(:options) { :company }
30
34
 
31
35
  it 'matches if the model accepts the nested attributes' do
32
- model.accepts_nested_attributes_for(*options)
33
- model.should accept_nested_attributes_for(*options)
36
+ model.accepts_nested_attributes_for *options
37
+ expect(model).to accept_nested_attributes_for *options
34
38
  end
35
39
 
36
40
  it 'does not match if the model does not accept the nested attributes' do
37
- model.should_not accept_nested_attributes_for(*options)
41
+ expect(model).to_not accept_nested_attributes_for *options
38
42
  end
39
43
  end
40
44
 
41
- with_option(:allow_destroy, true, false)
42
- with_option(:limit, 1, 2)
43
- with_option(:update_only, true, false)
45
+ with_option :allow_destroy, true, false
46
+ with_option :limit, 1, 2
47
+ with_option :update_only, true, false
44
48
 
45
- with_unsupported_option(:reject_if, :all_blank)
49
+ with_unsupported_option :reject_if, :all_blank
46
50
  end
47
51
  end
@@ -1,26 +1,26 @@
1
- require 'spec_helper'
2
-
3
1
  describe :belong_to do
4
2
  let(:macro) { :belongs_to }
5
- let(:options) { [:company, { :dependent => :destroy }] }
3
+ let(:options) { [:company, { dependent: :destroy }] }
6
4
 
7
5
  it_behaves_like 'an Active Record matcher' do
8
6
  let(:model) { build_class(:User, ActiveRecord::Base) }
9
7
 
8
+ subject(:instance) { model.new }
9
+
10
10
  before do
11
- create_table(:users) { |table| table.integer(:company_id) }
11
+ create_table :users do |table|
12
+ table.integer :company_id
13
+ end
12
14
  end
13
15
 
14
- subject { model.new }
15
-
16
16
  context 'description' do
17
17
  let(:matcher) { send(matcher_name, *options) }
18
18
 
19
19
  it 'has a custom description' do
20
- name = matcher.instance_variable_get(:@name).to_s.gsub(/_/, ' ')
21
- association = matcher.instance_variable_get(:@association)
22
- with = " with #{matcher.expected.inspect}" if matcher.expected.any?
23
- matcher.description.should == "#{name} #{association}#{with}"
20
+ association = matcher.attribute
21
+ with = " with #{matcher.options.inspect}" if matcher.options.any?
22
+
23
+ expect(matcher.description).to eq "belong to #{association}#{with}"
24
24
  end
25
25
  end
26
26
 
@@ -28,30 +28,30 @@ describe :belong_to do
28
28
  let(:options) { :company }
29
29
 
30
30
  it 'matches if the association exists' do
31
- model.belongs_to(*options)
32
- model.should belong_to(*options)
31
+ model.belongs_to *options
32
+ expect(model).to belong_to *options
33
33
  end
34
34
 
35
35
  it 'does not match if the association does not exist' do
36
- model.should_not belong_to(*options)
36
+ expect(model).to_not belong_to *options
37
37
  end
38
38
 
39
39
  it 'does not match if the association is of the wrong type' do
40
- model.has_many(*options)
41
- model.should_not belong_to(*options)
40
+ model.has_many *options
41
+ expect(model).to_not belong_to *options
42
42
  end
43
43
  end
44
44
 
45
- with_option(:class_name, 'Company', 'Organization')
46
- with_option(:foreign_key, :company_id, :organization_id)
47
- with_option(:foreign_type, :company_type, :organization_type)
48
- with_option(:primary_key, :id, :company_id)
49
- with_option(:dependent, :destroy, :nullify)
50
- with_option(:counter_cache, true, false)
51
- with_option(:polymorphic, true, false)
52
- with_option(:validate, true, false)
53
- with_option(:autosave, true, false)
54
- with_option(:touch, true, false)
55
- with_option(:inverse_of, :users, :employees)
45
+ with_option :class_name, 'Company', 'Organization'
46
+ with_option :foreign_key, :company_id, :organization_id
47
+ with_option :foreign_type, :company_type, :organization_type
48
+ with_option :primary_key, :id, :company_id
49
+ with_option :dependent, :destroy, :nullify
50
+ with_option :counter_cache, true, false
51
+ with_option :polymorphic, true, false
52
+ with_option :validate, true, false
53
+ with_option :autosave, true, false
54
+ with_option :touch, true, false
55
+ with_option :inverse_of, :users, :employees
56
56
  end
57
57
  end
@@ -1,25 +1,27 @@
1
- require 'spec_helper'
2
-
3
1
  describe :have_and_belong_to_many do
4
2
  let(:macro) { :has_and_belongs_to_many }
5
- let(:options) { [:tags, { :validate => true }] }
3
+ let(:options) { [:tags, { validate: true }] }
6
4
 
7
5
  it_behaves_like 'an Active Record matcher' do
8
6
  let(:model) { build_class(:User, ActiveRecord::Base) }
9
7
 
8
+ subject(:instance) { model.new }
9
+
10
10
  before do
11
- create_table(:users) { |table| table.string(:name) }
11
+ create_table :users do |table|
12
+ table.string :name
13
+ end
12
14
  end
13
15
 
14
- subject { model.new }
15
-
16
16
  context 'description' do
17
17
  let(:matcher) { send(matcher_name, *options) }
18
18
 
19
19
  it 'has a custom description' do
20
- association = matcher.instance_variable_get(:@association)
21
- with = " with #{matcher.expected.inspect}" if matcher.expected.any?
22
- matcher.description.should == "have and belong to #{association}#{with}"
20
+ association = matcher.attribute
21
+ with = " with #{matcher.options.inspect}" if matcher.options.any?
22
+
23
+ expect(matcher.description)
24
+ .to eq "have and belong to #{association}#{with}"
23
25
  end
24
26
  end
25
27
 
@@ -27,25 +29,25 @@ describe :have_and_belong_to_many do
27
29
  let(:options) { :tags }
28
30
 
29
31
  it 'matches if the association exists' do
30
- model.has_and_belongs_to_many(*options)
31
- model.should have_and_belong_to_many(*options)
32
+ model.has_and_belongs_to_many *options
33
+ expect(model).to have_and_belong_to_many *options
32
34
  end
33
35
 
34
36
  it 'does not match if the association does not exist' do
35
- model.should_not have_and_belong_to_many(*options)
37
+ expect(model).to_not have_and_belong_to_many *options
36
38
  end
37
39
 
38
40
  it 'does not match if the association is of the wrong type' do
39
- model.has_many(*options)
40
- model.should_not have_and_belong_to_many(*options)
41
+ model.has_many *options
42
+ expect(model).to_not have_and_belong_to_many *options
41
43
  end
42
44
  end
43
45
 
44
- with_option(:class_name, 'Tag', 'Role')
45
- with_option(:join_table, 'tags_users', 'user_tags')
46
- with_option(:foreign_key, :user_id, :tagged_id)
47
- with_option(:association_foreign_key, :tag_id, :role_id)
48
- with_option(:validate, true, false)
49
- with_option(:autosave, true, false)
46
+ with_option :class_name, 'Tag', 'Role'
47
+ with_option :join_table, 'tags_users', 'user_tags'
48
+ with_option :foreign_key, :user_id, :tagged_id
49
+ with_option :association_foreign_key, :tag_id, :role_id
50
+ with_option :validate, true, false
51
+ with_option :autosave, true, false
50
52
  end
51
53
  end
@@ -1,108 +1,105 @@
1
- require 'spec_helper'
2
-
3
1
  describe :have_column do
4
2
  let(:options) { :one }
5
3
 
6
4
  it_behaves_like 'an Active Record matcher' do
7
5
  let(:model) { build_class(:User, ActiveRecord::Base) }
8
6
 
7
+ subject(:instance) { model.new }
8
+
9
9
  before do
10
- create_table(:users) { |table| }
10
+ create_table :users
11
11
  end
12
12
 
13
- subject { model.new }
14
-
15
13
  context 'description' do
16
14
  let(:matcher) { send(matcher_name, *options) }
17
15
 
18
16
  it 'has a custom description' do
19
- name = matcher.instance_variable_get(:@name).to_s.gsub(/_/, ' ')
20
- with = " with #{matcher.expected}" if matcher.expected.any?
17
+ with = " with #{matcher.options}" if matcher.options.any?
21
18
 
22
- matcher.description.should == "#{name} #{options}#{with}"
19
+ expect(matcher.description).to eq "have column #{options}#{with}"
23
20
  end
24
21
  end
25
22
 
26
23
  context 'with a column' do
27
24
  it 'matches if the column exists' do
28
- ActiveRecord::Base.connection.add_column(:users, :one, :string)
29
- model.should have_column(:one)
25
+ ActiveRecord::Base.connection.add_column :users, :one, :string
26
+ expect(model).to have_column :one
30
27
  end
31
28
 
32
29
  it 'does not match if the column does not exist' do
33
- model.should_not have_column(:one)
30
+ expect(model).to_not have_column :one
34
31
  end
35
32
  end
36
33
 
37
34
  context 'with option :default' do
38
35
  it 'matches if the column exists' do
39
- ActiveRecord::Base.connection.add_column(:users, :one, :integer, :default => 1)
40
- model.should have_column(:one, :default => 1)
36
+ ActiveRecord::Base.connection.add_column :users, :one, :integer, default: 1
37
+ expect(model).to have_column :one, default: 1
41
38
  end
42
39
 
43
40
  it 'does not match if the column does not have the same default' do
44
- ActiveRecord::Base.connection.add_column(:users, :one, :integer, :default => 2)
45
- model.should_not have_column(:one, :default => 1)
41
+ ActiveRecord::Base.connection.add_column :users, :one, :integer, default: 2
42
+ expect(model).to_not have_column :one, default: 1
46
43
  end
47
44
  end
48
45
 
49
46
  context 'with option :limit' do
50
47
  it 'matches if the column exists' do
51
- ActiveRecord::Base.connection.add_column(:users, :one, :string, :limit => 10)
52
- model.should have_column(:one, :limit => 10)
48
+ ActiveRecord::Base.connection.add_column :users, :one, :string, limit: 10
49
+ expect(model).to have_column :one, limit: 10
53
50
  end
54
51
 
55
52
  it 'does not match if the column does not have the same limit' do
56
- ActiveRecord::Base.connection.add_column(:users, :one, :string, :limit => 5)
57
- model.should_not have_column(:one, :limit => 10)
53
+ ActiveRecord::Base.connection.add_column :users, :one, :string, limit: 5
54
+ expect(model).to_not have_column :one, limit: 10
58
55
  end
59
56
  end
60
57
 
61
58
  context 'with option :null' do
62
59
  it 'matches if the column exists' do
63
- ActiveRecord::Base.connection.add_column(:users, :one, :integer, :null => false, :default => 1)
64
- model.should have_column(:one, :null => false)
60
+ ActiveRecord::Base.connection.add_column :users, :one, :integer, null: false, default: 1
61
+ expect(model).to have_column :one, null: false
65
62
  end
66
63
 
67
64
  it 'does not match if the column does not have the same null' do
68
- ActiveRecord::Base.connection.add_column(:users, :one, :integer)
69
- model.should_not have_column(:one, :null => false)
65
+ ActiveRecord::Base.connection.add_column :users, :one, :integer
66
+ expect(model).to_not have_column :one, null: false
70
67
  end
71
68
  end
72
69
 
73
70
  context 'with option :precision' do
74
71
  it 'matches if the column exists' do
75
- ActiveRecord::Base.connection.add_column(:users, :one, :decimal, :precision => 8)
76
- model.should have_column(:one, :precision => 8)
72
+ ActiveRecord::Base.connection.add_column :users, :one, :decimal, precision: 8
73
+ expect(model).to have_column :one, precision: 8
77
74
  end
78
75
 
79
76
  it 'does not match if the column does not have the same null' do
80
- ActiveRecord::Base.connection.add_column(:users, :one, :decimal, :precision => 8)
81
- model.should_not have_column(:one, :precision => 5)
77
+ ActiveRecord::Base.connection.add_column :users, :one, :decimal, precision: 8
78
+ expect(model).to_not have_column :one, precision: 5
82
79
  end
83
80
  end
84
81
 
85
82
  context 'with option :scale' do
86
83
  it 'matches if the column exists' do
87
- ActiveRecord::Base.connection.add_column(:users, :one, :decimal, :precision => 8, :scale => 2)
88
- model.should have_column(:one, :scale => 2)
84
+ ActiveRecord::Base.connection.add_column :users, :one, :decimal, precision: 8, scale: 2
85
+ expect(model).to have_column :one, scale: 2
89
86
  end
90
87
 
91
88
  it 'does not match if the column does not have the same null' do
92
- ActiveRecord::Base.connection.add_column(:users, :one, :decimal, :precision => 8, :scale => 2)
93
- model.should_not have_column(:one, :scale => 3)
89
+ ActiveRecord::Base.connection.add_column :users, :one, :decimal, precision: 8, scale: 2
90
+ expect(model).to_not have_column :one, scale: 3
94
91
  end
95
92
  end
96
93
 
97
94
  context 'with option :type' do
98
95
  it 'matches if the column exists' do
99
- ActiveRecord::Base.connection.add_column(:users, :one, :integer)
100
- model.should have_column(:one, :type => :integer)
96
+ ActiveRecord::Base.connection.add_column :users, :one, :integer
97
+ expect(model).to have_column :one, type: :integer
101
98
  end
102
99
 
103
100
  it 'does not match if the column does not have the same type' do
104
- ActiveRecord::Base.connection.add_column(:users, :one, :string)
105
- model.should_not have_column(:one, :type => :integer)
101
+ ActiveRecord::Base.connection.add_column :users, :one, :string
102
+ expect(model).to_not have_column :one, type: :integer
106
103
  end
107
104
  end
108
105
  end