active_record_ignored_attributes 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8a097aef64bf78c8e590506619696287d411de3a
4
+ data.tar.gz: 4ba8095ef7e9a8611f72067cd59bacf3369d3dbe
5
+ SHA512:
6
+ metadata.gz: e06f85d8d9f77093b48bed38ed047c3e5bb0c3b5696df00cdb9063ad1c97d9ca8cae4c70251db65fad0303141d13762d0441bc44fecd78d2630d23a579e97e61
7
+ data.tar.gz: 20c40c2c34a831e17d6b3d7af075198f2c703a6bbd6e24240fd9962736429e281780f60868816c92e54faf5728521608f610706ed32f4ad2bbf865888cac47ce
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .idea
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in active_record_ignored_attributes.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'byebug'
8
+ end
data/Readme.md CHANGED
@@ -1,7 +1,10 @@
1
1
  ActiveRecord Ignored Attributes
2
2
  ===============================
3
3
 
4
- Adds various behavior to Active Record models relating to the model's attributes:
4
+ Updated to work with RSpec 3.x
5
+
6
+
7
+ Adds various behavior to Active Record models relating to the model's attributes:
5
8
 
6
9
  * Allows you to compare Active Record objects based on their *attributes*, which often makes more sense than the built-in `==` operator (which does its comparisons based on the `id` attribute alone! — not always what you want!)
7
10
  * You can configure which attributes, if any, should be excluded from the comparison
@@ -102,7 +105,7 @@ Now that you've declared which attributes you don't really care about, how about
102
105
 
103
106
  # Compared to:
104
107
  address.inspect # => "#<Address id: 1, name: nil, address: nil, city: nil, state: nil, postal_code: nil, country: nil, created_at: \"2011-08-19 18:07:39\", updated_at: \"2011-08-19 18:07:39\">"
105
-
108
+
106
109
  But that is a lot to type every time. If you want inspect to *always* be more readable, you can override the ActiveRecord default like this:
107
110
 
108
111
  class Address < ActiveRecord::Base
@@ -227,7 +230,7 @@ Questions and Ideas
227
230
 
228
231
  Possible improvements:
229
232
 
230
- * Allow the default to be overridden with a class macro like `ignore_for_attributes_eql :last_signed_in_at, :updated_at`
233
+ * Allow the default to be overridden with a class macro like `ignore_for_attributes_eql :last_signed_in_at, :updated_at`
231
234
 
232
235
  Also, perhaps you want to set the default ignored attributes for a model but still wish to be able to override these defaults as needed...
233
236
 
@@ -14,13 +14,12 @@ Gem::Specification.new do |s|
14
14
  s.add_dependency 'activerecord'
15
15
  s.add_dependency 'facets'
16
16
 
17
- s.add_development_dependency 'rspec'
18
- #s.add_development_dependency 'rcov'
17
+ s.add_development_dependency 'rake'
18
+ s.add_development_dependency 'rspec', '~> 3'
19
19
  s.add_development_dependency 'sqlite3'
20
- s.add_development_dependency 'mysql2', '~>0.2.11'
20
+ s.add_development_dependency 'mysql2'
21
21
  s.add_development_dependency 'rr'
22
- s.add_development_dependency 'activesupport'
23
- s.add_development_dependency 'ruby-debug19'
22
+ s.add_development_dependency 'activesupport', '~> 4'
24
23
 
25
24
  s.files = `git ls-files`.split("\n")
26
25
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -3,7 +3,7 @@ RSpec::Matchers.define :be_same_as do |expected|
3
3
  actual.same_as?(expected)
4
4
  end
5
5
 
6
- failure_message_for_should do |actual|
6
+ failure_message do |actual|
7
7
  #%(#{actual.inspect_without_ignored_attributes} was expected to have the same attributes as\n) +
8
8
  #%(#{expected.inspect_without_ignored_attributes})
9
9
 
@@ -15,7 +15,7 @@ RSpec::Matchers.define :be_same_as do |expected|
15
15
  %( got: #{actual.inspect_with(attr_names_that_differed)})
16
16
  end
17
17
 
18
- failure_message_for_should_not do |actual|
18
+ failure_message_when_negated do |actual|
19
19
  %( expected: #{expected.inspect}\n) +
20
20
  %(to not be same_as: #{actual.inspect})
21
21
  end
@@ -3,12 +3,12 @@ RSpec::Matchers.define :have_attribute_values do |expected|
3
3
  actual.has_attribute_values?(expected)
4
4
  end
5
5
 
6
- failure_message_for_should do |actual|
6
+ failure_message do |actual|
7
7
  %(expected: #{expected.symbolize_keys.inspect}\n) +
8
8
  %( got: #{actual.attributes.slice(*expected.stringify_keys.keys).symbolize_keys.inspect})
9
9
  end
10
10
 
11
- failure_message_for_should_not do |actual|
11
+ failure_message_when_negated do |actual|
12
12
  %(expected #{actual.inspect}\n) +
13
13
  %(not to have attribute values #{expected.symbolize_keys.inspect})
14
14
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecordIgnoredAttributes
2
2
  def self.version
3
- "0.0.4"
3
+ "0.0.5"
4
4
  end
5
5
  end
@@ -5,28 +5,28 @@ describe Address do
5
5
  let(:address) { Address.create! }
6
6
  it 'should not include any of the ignored attributes' do
7
7
  address.attributes_without_ignored_attributes.tap do |attributes|
8
- attributes.should be_a(Hash)
9
- attributes.should_not have_key('id')
10
- attributes.should_not have_key('created_at')
11
- attributes.should_not have_key('updated_at')
12
- attributes.should_not have_key('name')
8
+ expect(attributes.class).to eq(Hash)
9
+ expect(attributes).to_not have_key('id')
10
+ expect(attributes).to_not have_key('created_at')
11
+ expect(attributes).to_not have_key('updated_at')
12
+ expect(attributes).to_not have_key('name')
13
13
  end
14
14
 
15
15
  # Plain old 'attributes', on the other hand, does include them
16
16
  address.attributes.tap do |attributes|
17
- attributes.should be_a(Hash)
18
- attributes.should have_key('id')
19
- attributes.should have_key('created_at')
20
- attributes.should have_key('updated_at')
17
+ expect(attributes.class).to eq(Hash)
18
+ expect(attributes).to have_key('id')
19
+ expect(attributes).to have_key('created_at')
20
+ expect(attributes).to have_key('updated_at')
21
21
  end
22
22
  end
23
23
 
24
24
  it 'should include all of the non-ignored attributes' do
25
25
  address.attributes_without_ignored_attributes.tap do |attributes|
26
- attributes.should be_a(Hash)
26
+ expect(attributes.class).to eq(Hash)
27
27
  [:address, :city, :state, :postal_code, :country].each do |attr_name|
28
28
  #puts "attributes.has_key?(#{attr_name})=#{attributes.has_key?(attr_name)}"
29
- attributes.should have_key(attr_name.to_s)
29
+ expect(attributes).to have_key(attr_name.to_s)
30
30
  end
31
31
  end
32
32
  end
@@ -6,18 +6,18 @@ describe Address do
6
6
 
7
7
  it 'should return true if passed {}' do
8
8
  a = Address.new( name: 'A', address: 'The Same Address', city: "Don't care")
9
- a.has_attribute_values?({}).should be_true
9
+ expect(a.has_attribute_values?({})).to be(true)
10
10
  end
11
11
 
12
12
  it 'should return true if the given attributes have the given values' do
13
13
  a = Address.new( name: 'A', address: 'The Same Address', city: "Don't care")
14
- a.has_attribute_values?(name: 'A', address: 'The Same Address').should be_true
14
+ expect(a.has_attribute_values?(name: 'A', address: 'The Same Address')).to be(true)
15
15
  end
16
16
 
17
17
  it 'should return false if any of the given attributes have different values than given' do
18
18
  a = Address.new( name: 'A', address: 'The Same Address', city: "Don't care")
19
- a.has_attribute_values?(name: 'A', address: 'The Same Address', city: "I do care after all").should be_false
20
- a.has_attribute_values?(name: 'B', address: 'The Same Address').should be_false
19
+ expect(a.has_attribute_values?(name: 'A', address: 'The Same Address', city: "I do care after all")).to be(false)
20
+ expect(a.has_attribute_values?(name: 'B', address: 'The Same Address')).to be(false)
21
21
  end
22
22
  end
23
23
  end
@@ -4,22 +4,23 @@ describe Address do
4
4
  describe 'inspect_without_ignored_attributes' do
5
5
  let(:address) { Address.create }
6
6
  it "should include id" do
7
- address.inspect_without_ignored_attributes.should match(/id:/)
7
+ expect(address.inspect_without_ignored_attributes).to match(/id:/)
8
8
  end
9
9
  it "should not include the other ignored_attributes" do
10
- address.inspect_without_ignored_attributes.should_not match(/name:/)
11
- address.inspect_without_ignored_attributes.should_not match(/created_at:/)
10
+ expect(address.inspect_without_ignored_attributes).to_not match(/name:/)
11
+ expect(address.inspect_without_ignored_attributes).to_not match(/created_at:/)
12
12
  end
13
13
  it "should match what we expect it to look like" do
14
- address.inspect_without_ignored_attributes.should match(/#<Address id: \d+, address: nil, city: nil, country: nil, postal_code: nil, state: nil>/)
15
- address.original_inspect.should match(/#<Address id: \d+, .* created_at: ".*", updated_at: ".*">/)
14
+ m = /Addressid:\d+, address:nil, city:nil, country:nil, postal_code:nil, state:nil/
15
+ expect(address.inspect_without_ignored_attributes.gsub(/[<>#]/,'').gsub(/\s/, '').split(/,/).sort.to_s.gsub(/["\]\[]/,'')).to match(m)
16
+ expect(address.original_inspect).to match(/#<Address id: \d+, .* created_at: ".*", updated_at: ".*">/)
16
17
  end
17
18
  end
18
19
 
19
20
  describe 'inspect' do
20
21
  let(:address) { Address.create }
21
22
  specify do
22
- address.inspect.should match(/{Address id: \d+, name: nil, address: nil, city: nil, state: nil, postal_code: nil, country: nil}/)
23
+ expect(address.inspect).to match(/{Address id: \d+, name: nil, address: nil, city: nil, state: nil, postal_code: nil, country: nil}/)
23
24
  end
24
25
  end
25
26
  end
@@ -6,30 +6,30 @@ describe "have_attribute_values" do
6
6
  it "delegates to has_attribute_values?" do
7
7
  object, other = Object.new, Object.new
8
8
  mock(object).has_attribute_values?(other) { true }
9
- object.should have_attribute_values(other)
9
+ expect(object).to have_attribute_values(other)
10
10
  end
11
11
 
12
12
  it 'matches when it should match' do
13
13
  object = Address.new( name: 'A', address: 'The Same Address', city: "Don't care")
14
14
  expect do
15
- (object.should have_attribute_values name: 'A', address: 'The Same Address').should be_true
15
+ expect(object).to have_attribute_values(name: 'A', address: 'The Same Address')
16
16
  end.to_not raise_error
17
17
  end
18
18
 
19
- it "reports a nice failure message for should" do
19
+ it "reports a nice failure message for to" do
20
20
  object = Address.new( name: 'A', address: 'The Same Address', city: "Don't care")
21
21
  expect do
22
- object.should have_attribute_values name: 'A', address: 'A Slightly Different Address'
22
+ expect(object).to have_attribute_values name: 'A', address: 'A Slightly Different Address'
23
23
  end.to raise_error(<<-End.strip_heredoc.chomp)
24
24
  expected: {:name=>"A", :address=>"A Slightly Different Address"}
25
25
  got: {:name=>"A", :address=>"The Same Address"}
26
26
  End
27
27
  end
28
28
 
29
- it "reports a nice failure message for should_not" do
29
+ it "reports a nice failure message for to_not" do
30
30
  object = Address.new( name: 'A', address: 'The Same Address', city: "Don't care")
31
31
  expect do
32
- object.should_not have_attribute_values name: 'A', address: 'The Same Address'
32
+ expect(object).to_not have_attribute_values(name: 'A', address: 'The Same Address')
33
33
  end.to raise_error(<<-End.strip_heredoc.chomp)
34
34
  expected {Address id: nil, name: "A", address: "The Same Address", city: "Don't care", state: nil, postal_code: nil, country: nil}
35
35
  not to have attribute values {:name=>"A", :address=>"The Same Address"}
@@ -5,23 +5,23 @@ describe "be_same_as" do
5
5
  it "delegates to same_as?" do
6
6
  object, other = Object.new, Object.new
7
7
  mock(object).same_as?(other) { true }
8
- object.should be_same_as(other)
8
+ expect(object).to be_same_as(other)
9
9
  end
10
10
 
11
- it "reports a nice failure message for should" do
11
+ it "reports a nice failure message for to" do
12
12
  object, other = Address.new(address: 'A Street'), Address.new(address: 'B Street')
13
13
  expect do
14
- object.should be_same_as(other)
14
+ expect(object).to be_same_as(other)
15
15
  end.to raise_error(<<-End.strip_heredoc.chomp)
16
16
  expected: #<Address address: "B Street">
17
17
  got: #<Address address: "A Street">
18
18
  End
19
19
  end
20
20
 
21
- it "reports a nice failure message for should_not" do
21
+ it "reports a nice failure message for to_not" do
22
22
  object, other = Address.new(address: 'A Street'), Address.new(address: 'A Street')
23
23
  expect do
24
- object.should_not be_same_as(other)
24
+ expect(object).to_not be_same_as(other)
25
25
  end.to raise_error(<<-End.strip_heredoc.chomp)
26
26
  expected: {Address id: nil, name: nil, address: "A Street", city: nil, state: nil, postal_code: nil, country: nil}
27
27
  to not be same_as: {Address id: nil, name: nil, address: "A Street", city: nil, state: nil, postal_code: nil, country: nil}
@@ -8,18 +8,18 @@ describe Address do
8
8
  a = Address.new(address: '123 A Street')
9
9
  b = Address.new(address: '345 K Street')
10
10
 
11
- a.should_not be_same_as(b)
12
- a.attributes.should_not == b.attributes
13
- a.attributes_without_ignored_attributes.should_not == b.attributes_without_ignored_attributes
11
+ expect(a).to_not be_same_as(b)
12
+ expect(a.attributes).to_not eq(b.attributes)
13
+ expect(a.attributes_without_ignored_attributes).to_not eq(b.attributes_without_ignored_attributes)
14
14
  end
15
15
 
16
16
  it 'should still return true even if some of the ignored attributes differ' do
17
17
  a = Address.new(name: 'A', address: 'The Same Address')
18
18
  b = Address.new(name: 'B', address: 'The Same Address')
19
19
 
20
- a.should be_same_as(b)
21
- a.attributes.should_not == b.attributes
22
- a.attributes_without_ignored_attributes.should == b.attributes_without_ignored_attributes
20
+ expect(a).to be_same_as(b)
21
+ expect(a.attributes).to_not eq(b.attributes)
22
+ expect(a.attributes_without_ignored_attributes).to eq(b.attributes_without_ignored_attributes)
23
23
  end
24
24
  end
25
25
  end
@@ -1,3 +1,6 @@
1
+ require 'yaml'
2
+ require 'byebug'
3
+
1
4
  __DIR__ = Pathname.new(__FILE__).dirname
2
5
  $LOAD_PATH.unshift __DIR__
3
6
  $LOAD_PATH.unshift __DIR__ + '../lib'
@@ -6,7 +6,7 @@ ActiveRecord::Schema.define do
6
6
  t.string :state
7
7
  t.string :postal_code
8
8
  t.string :country
9
- t.timestamps
9
+ t.timestamps null:false
10
10
  end
11
11
  end
12
12
 
metadata CHANGED
@@ -1,104 +1,127 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_ignored_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tyler Rick
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-11-29 00:00:00.000000000 Z
11
+ date: 2015-03-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
- requirement: &14080760 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *14080760
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: facets
27
- requirement: &14079980 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - ">="
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *14079980
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
36
41
  - !ruby/object:Gem::Dependency
37
- name: rspec
38
- requirement: &14095640 !ruby/object:Gem::Requirement
39
- none: false
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
- - - ! '>='
45
+ - - ">="
42
46
  - !ruby/object:Gem::Version
43
47
  version: '0'
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *14095640
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
47
69
  - !ruby/object:Gem::Dependency
48
70
  name: sqlite3
49
- requirement: &14094940 !ruby/object:Gem::Requirement
50
- none: false
71
+ requirement: !ruby/object:Gem::Requirement
51
72
  requirements:
52
- - - ! '>='
73
+ - - ">="
53
74
  - !ruby/object:Gem::Version
54
75
  version: '0'
55
76
  type: :development
56
77
  prerelease: false
57
- version_requirements: *14094940
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
58
83
  - !ruby/object:Gem::Dependency
59
84
  name: mysql2
60
- requirement: &14094320 !ruby/object:Gem::Requirement
61
- none: false
85
+ requirement: !ruby/object:Gem::Requirement
62
86
  requirements:
63
- - - ~>
87
+ - - ">="
64
88
  - !ruby/object:Gem::Version
65
- version: 0.2.11
89
+ version: '0'
66
90
  type: :development
67
91
  prerelease: false
68
- version_requirements: *14094320
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rr
71
- requirement: &14093860 !ruby/object:Gem::Requirement
72
- none: false
99
+ requirement: !ruby/object:Gem::Requirement
73
100
  requirements:
74
- - - ! '>='
101
+ - - ">="
75
102
  - !ruby/object:Gem::Version
76
103
  version: '0'
77
104
  type: :development
78
105
  prerelease: false
79
- version_requirements: *14093860
80
- - !ruby/object:Gem::Dependency
81
- name: activesupport
82
- requirement: &14093300 !ruby/object:Gem::Requirement
83
- none: false
106
+ version_requirements: !ruby/object:Gem::Requirement
84
107
  requirements:
85
- - - ! '>='
108
+ - - ">="
86
109
  - !ruby/object:Gem::Version
87
110
  version: '0'
88
- type: :development
89
- prerelease: false
90
- version_requirements: *14093300
91
111
  - !ruby/object:Gem::Dependency
92
- name: ruby-debug19
93
- requirement: &14092880 !ruby/object:Gem::Requirement
94
- none: false
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
95
114
  requirements:
96
- - - ! '>='
115
+ - - "~>"
97
116
  - !ruby/object:Gem::Version
98
- version: '0'
117
+ version: '4'
99
118
  type: :development
100
119
  prerelease: false
101
- version_requirements: *14092880
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4'
102
125
  description: Allows you to compare Active Record objects based on their *attributes*
103
126
  (with same_as?), to exclude some attributes from being used in comparison, and adds
104
127
  improved inspect method
@@ -108,8 +131,8 @@ executables: []
108
131
  extensions: []
109
132
  extra_rdoc_files: []
110
133
  files:
111
- - .gitignore
112
- - .rspec
134
+ - ".gitignore"
135
+ - ".rspec"
113
136
  - Gemfile
114
137
  - Rakefile
115
138
  - Readme.md
@@ -136,29 +159,27 @@ files:
136
159
  - spec/support/schema.rb
137
160
  homepage: ''
138
161
  licenses: []
162
+ metadata: {}
139
163
  post_install_message:
140
164
  rdoc_options: []
141
165
  require_paths:
142
166
  - lib
143
167
  required_ruby_version: !ruby/object:Gem::Requirement
144
- none: false
145
168
  requirements:
146
- - - ! '>='
169
+ - - ">="
147
170
  - !ruby/object:Gem::Version
148
171
  version: '0'
149
172
  required_rubygems_version: !ruby/object:Gem::Requirement
150
- none: false
151
173
  requirements:
152
- - - ! '>='
174
+ - - ">="
153
175
  - !ruby/object:Gem::Version
154
176
  version: '0'
155
177
  requirements: []
156
178
  rubyforge_project:
157
- rubygems_version: 1.8.15
179
+ rubygems_version: 2.4.5
158
180
  signing_key:
159
- specification_version: 3
181
+ specification_version: 4
160
182
  summary: Allows you to compare Active Record objects based on their *attributes* (with
161
183
  same_as?), to exclude some attributes from being used in comparison, and adds improved
162
184
  inspect method
163
185
  test_files: []
164
- has_rdoc: