HornsAndHooves-moribus 0.6.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 664930f1565d0d6eaa50dc8fba6c3f90763e70c709a748f2e572f493ef2f3de5
4
- data.tar.gz: b9541ec330424313c0e71f9605af2f2cf615d6df92b2a29961a97675cc457683
3
+ metadata.gz: f9ed8306d0cb942466108234ba8408229a24b58155a0d49766343474f9b4f846
4
+ data.tar.gz: 44c7ecd497ac5cb564874f5278cd24ecfaf708cecd1efd65d12b7159c80f7ffc
5
5
  SHA512:
6
- metadata.gz: 5af699607d6d67710af3e538cc23138b0a934236c5ce2b234ebc9a3349f989c6e7eaa1184a9608d5b3f77e5ff2898d2f96757d5805d39e7a1d4af349947cbef3
7
- data.tar.gz: 7a8cec103bc680b45800f888adfda114b7cbe55d3ef5547694f2227cd79afff4f2e3b503782ae79b84f8beab7a80b6c0452369d464c8c8a9daf01e9c3c8335b3
6
+ metadata.gz: 9fa73e79e461f240134469e04c80a5f6d7baddb9b0638e010ddd24b2316c9123ebb25d220dccd80463f689f340fbe92b05795a2786e8e317fc780d787c872a0d
7
+ data.tar.gz: 96b2e59ab096002ab9ddb9c1e88305aa9c0127f61f4c19d75eb63206def9a8e8dceb4ce13e13a9aeb53ec4733167d3792a2facf582f695862dd599d42333656a
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.6
1
+ 2.6.6
data/.simplecov CHANGED
@@ -12,7 +12,7 @@ SimpleCov.start do
12
12
  # Fail the build when coverage is weak:
13
13
  at_exit do
14
14
  SimpleCov.result.format!
15
- threshold, actual = 99.751, SimpleCov.result.covered_percent
15
+ threshold, actual = 100, SimpleCov.result.covered_percent
16
16
  if actual < threshold
17
17
  msg = "\nLow coverage: "
18
18
  msg << red("#{actual}%")
@@ -20,12 +20,12 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  # specify any dependencies here; for example:
23
- s.add_dependency "rails", "> 4.0", "< 5"
23
+ s.add_dependency "rails", "~> 6"
24
24
  s.add_dependency "power_enum", ">= 2.7.0"
25
25
  s.add_dependency "yard", ">= 0"
26
26
 
27
27
  s.add_development_dependency "rake"
28
28
  s.add_development_dependency "rspec"
29
29
  s.add_development_dependency "rspec-rails"
30
- s.add_development_dependency "sqlite3", "~> 1.3.6"
30
+ s.add_development_dependency "sqlite3"
31
31
  end
@@ -31,7 +31,7 @@ module Moribus
31
31
  class_attribute :aggregated_records_cache
32
32
  self.aggregated_records_cache = {}
33
33
 
34
- after_save :cache_aggregated_record, :on => :create
34
+ after_save :cache_aggregated_record
35
35
  end
36
36
 
37
37
  # Class methods for model that includes AggregatedCacheBehavior
@@ -23,30 +23,25 @@ module Moribus
23
23
  # association-specific methods. See module description for example.
24
24
  def alias_association(alias_name, association_name)
25
25
  if reflection = reflect_on_association(association_name)
26
- # Use Rails 4.1.x+ behavior, if available:
27
- if ActiveRecord::Reflection.respond_to? :add_reflection then
28
- ActiveRecord::Reflection.add_reflection self, alias_name, reflection
29
- else
30
- # Rails 4.0.x behavior:
31
- reflections[alias_name] = reflections[association_name]
32
- end
26
+ ActiveRecord::Reflection.add_reflection self, alias_name, reflection
27
+
33
28
  alias_association_methods(alias_name, reflection)
34
29
  reflection
35
30
  end
36
31
  end
37
32
 
38
33
  # Allows :alias option to alias belongs_to association
39
- def belongs_to(name, scope = nil, options = {})
34
+ def belongs_to(name, scope = nil, **options)
40
35
  options = scope if scope.is_a?(Hash)
41
36
 
42
37
  alias_name = options.delete(:alias)
43
- reflection = super(name, scope, options)
38
+ reflection = super(name, scope, **options)
44
39
  alias_association(alias_name, name) if alias_name
45
40
  reflection
46
41
  end
47
42
 
48
43
  # Allows :alias option to alias has_many association
49
- def has_many(name, scope = nil, options = {}, &extension)
44
+ def has_many(name, scope = nil, **options, &extension)
50
45
  options = scope if scope.is_a?(Hash)
51
46
 
52
47
  alias_name = options.delete(:alias)
@@ -56,7 +51,7 @@ module Moribus
56
51
  end
57
52
 
58
53
  # Allows :alias option to alias has_one association
59
- def has_one(name, scope = nil, options = {})
54
+ def has_one(name, scope = nil, **options)
60
55
  options = scope if scope.is_a?(Hash)
61
56
 
62
57
  alias_name = options.delete(:alias)
@@ -33,7 +33,7 @@ module Moribus
33
33
  # presented in Customer, the code will result in exception without
34
34
  # the following hook:
35
35
  def column_for_attribute(name)
36
- unless (column = super).nil?
36
+ unless (column = super).nil? || column.is_a?(ActiveRecord::ConnectionAdapters::NullColumn)
37
37
  return column
38
38
  end
39
39
 
@@ -71,7 +71,7 @@ module Moribus
71
71
  [name, "#{name}="]
72
72
  end
73
73
  klass.define_attribute_methods
74
- attribute_methods = klass.generated_attribute_methods.instance_methods.select{ |m| m !~ EXCLUDE_METHODS_REGEXP }
74
+ attribute_methods = klass.__send__(:generated_attribute_methods).instance_methods.select{ |m| m !~ EXCLUDE_METHODS_REGEXP }
75
75
  custom_writers = klass.instance_methods(false).map(&:to_s) & klass.column_names.map{ |name| "#{name}=" }
76
76
  (attribute_methods + enum_methods.flatten + custom_writers).map(&:to_sym)
77
77
  end
@@ -11,14 +11,12 @@ module Moribus
11
11
  else
12
12
  # Use custom update to avoid running ActiveRecord optimistic locking
13
13
  # and to avoid updating lock_version column:
14
- klass = target.class
15
- is_current_col = klass.columns.detect { |c| c.name == "is_current" }
16
- id_column = klass.columns.detect { |c| c.name == klass.primary_key }
14
+ klass = target.class
17
15
 
18
16
  sql = "UPDATE #{klass.quoted_table_name} " \
19
- "SET \"is_current\" = #{klass.quote_value(false, is_current_col)} "
17
+ "SET \"is_current\" = #{klass.connection.quote(false)} "
20
18
  sql << "WHERE #{klass.quoted_primary_key} = " \
21
- "#{klass.quote_value(target.send(klass.primary_key), id_column)} "
19
+ "#{klass.connection.quote(target.send(klass.primary_key))} "
22
20
 
23
21
  klass.connection.update sql
24
22
  end
@@ -116,7 +116,6 @@ module Moribus
116
116
  # TODO: need to find way to track stale objects
117
117
  def current_to_false_sql_statement
118
118
  klass = self.class
119
- is_current_col = klass.columns.detect { |c| c.name == "is_current" }
120
119
  lock_column_name = klass.locking_column
121
120
  lock_value = current_lock_value
122
121
  lock_column = if lock_value
@@ -124,17 +123,16 @@ module Moribus
124
123
  else
125
124
  nil
126
125
  end
127
- id_column = klass.columns.detect { |c| c.name == klass.primary_key }
128
126
  quoted_lock_column = klass.connection.quote_column_name(lock_column_name)
129
127
 
130
128
  "UPDATE #{klass.quoted_table_name} " \
131
- "SET \"is_current\" = #{klass.quote_value(false, is_current_col)} ".tap do |sql|
129
+ "SET \"is_current\" = #{klass.connection.quote(false)} ".tap do |sql|
132
130
  sql << "WHERE #{klass.quoted_primary_key} = " \
133
- "#{klass.quote_value(@_before_to_new_record_values[:id], id_column)}"
131
+ "#{klass.connection.quote(@_before_to_new_record_values[:id])}"
134
132
 
135
133
  if lock_value
136
- sql << " AND \"is_current\" = #{klass.quote_value(true, is_current_col)}"
137
- sql << " AND #{quoted_lock_column} = #{klass.quote_value(lock_value, lock_column)}"
134
+ sql << " AND \"is_current\" = #{klass.connection.quote(true)}"
135
+ sql << " AND #{quoted_lock_column} = #{klass.connection.quote(lock_value)}"
138
136
  end
139
137
  end
140
138
  end
@@ -1,3 +1,3 @@
1
1
  module Moribus # :nodoc:
2
- VERSION = "0.6.0" # :nodoc:
2
+ VERSION = "0.8.0" # :nodoc:
3
3
  end
data/lib/moribus.rb CHANGED
@@ -96,9 +96,13 @@ module Moribus
96
96
  self.id = existing.id
97
97
  self.created_at = existing.created_at if respond_to?(:created_at)
98
98
  self.updated_at = existing.updated_at if respond_to?(:updated_at)
99
- @changed_attributes = {}
99
+
100
+ clear_changes_information
100
101
  else
101
102
  restore_before_to_new_record_values
103
+
104
+ clear_attribute_change(:created_at) if respond_to?(:created_at)
105
+ clear_attribute_change(:updated_at) if respond_to?(:updated_at)
102
106
  end
103
107
  @new_record = false
104
108
  true
@@ -145,14 +149,12 @@ module Moribus
145
149
 
146
150
  if respond_to?(:updated_at=)
147
151
  self.updated_at = nil
148
- @changed_attributes =
149
- ActiveSupport::HashWithIndifferentAccess.new(changed_attributes.dup.merge(updated_at: nil))
152
+ self.updated_at_will_change!
150
153
  end
151
154
 
152
155
  if respond_to?(:created_at=)
153
156
  self.created_at = nil
154
- @changed_attributes =
155
- ActiveSupport::HashWithIndifferentAccess.new(changed_attributes.dup.merge(created_at: nil))
157
+ self.created_at_will_change!
156
158
  end
157
159
 
158
160
  # mark all other attributes is changing
@@ -0,0 +1,5 @@
1
+ // Sprockets 4.0+ requires this file to define asset paths.
2
+
3
+ //= link_tree ../images
4
+ //= link_directory ../javascripts .js
5
+ //= link_directory ../stylesheets .css
@@ -0,0 +1 @@
1
+ 02c924139ba4207bce788dd378b8f1f99976099325bbad4e85204e34d04970e039409db0f08ceea070238f4f5a41bdbc94fb6e51aeb0996a4ee32bcd3c31ede1
@@ -93,7 +93,7 @@ describe Moribus::AggregatedBehavior do
93
93
 
94
94
  it "looks up self and replaces id with existing on update" do
95
95
  name = SpecPersonName.create first_name: "Alice", last_name: "Smith"
96
- name.update_attributes first_name: "John"
96
+ name.update! first_name: "John"
97
97
  expect(name.id).to eq @existing.id
98
98
  end
99
99
 
@@ -132,5 +132,9 @@ describe Moribus::Extensions::DelegateAssociated do
132
132
  it "returns class db column if it exists" do
133
133
  expect(customer.column_for_attribute(:id)).not_to be_nil
134
134
  end
135
+
136
+ it "returns class db column if it doesn't exist" do
137
+ expect(customer.column_for_attribute(:foobar)).to be_nil
138
+ end
135
139
  end
136
140
  end
data/spec/moribus_spec.rb CHANGED
@@ -128,7 +128,7 @@ describe Moribus do
128
128
 
129
129
  suppress(Exception) do
130
130
  expect {
131
- @info.update_attributes spec_customer_id: nil, spec_person_name_id: 2
131
+ @info.update! spec_customer_id: nil, spec_person_name_id: 2
132
132
  }.not_to change(SpecCustomerInfo, :count)
133
133
  end
134
134
 
@@ -155,25 +155,25 @@ describe Moribus do
155
155
 
156
156
  it "creates a new current record if updated" do
157
157
  expect {
158
- @info.update_attributes(spec_person_name_id: 2)
158
+ @info.update!(spec_person_name_id: 2)
159
159
  }.to change(SpecCustomerInfo, :count).by(1)
160
160
  end
161
161
 
162
162
  it "replaces itself with new id" do
163
163
  old_id = @info.id
164
- @info.update_attributes(spec_person_name_id: 2)
164
+ @info.update!(spec_person_name_id: 2)
165
165
  expect(@info.id).not_to eq old_id
166
166
  end
167
167
 
168
168
  it "sets is_current record to false for superseded record" do
169
169
  old_id = @info.id
170
- @info.update_attributes(spec_person_name_id: 2)
170
+ @info.update!(spec_person_name_id: 2)
171
171
  expect(SpecCustomerInfo.find(old_id).is_current).to eq false
172
172
  end
173
173
 
174
174
  it "sets previous_id to the id of the previous record" do
175
175
  old_id = @info.id
176
- @info.update_attributes(spec_person_name_id: 2)
176
+ @info.update!(spec_person_name_id: 2)
177
177
  expect(@info.previous_id).to eq old_id
178
178
  end
179
179
 
@@ -191,7 +191,7 @@ describe Moribus do
191
191
  status: "unverified",
192
192
  is_current: true
193
193
  )
194
- expect{ email.update_attributes(status: "verified") }.not_to raise_error
194
+ expect{ email.update!(status: "verified") }.not_to raise_error
195
195
  end
196
196
 
197
197
  describe "updated_at and created_at" do
@@ -221,41 +221,41 @@ describe Moribus do
221
221
  end
222
222
 
223
223
  it "raises a stale object error" do
224
- @info1.update_attributes(spec_person_name_id: 3)
224
+ @info1.update!(spec_person_name_id: 3)
225
225
 
226
- expect{ @info2.update_attributes(spec_person_name_id: 4) }.
226
+ expect{ @info2.update!(spec_person_name_id: 4) }.
227
227
  to raise_error(ActiveRecord::StaleObjectError,
228
- "Attempted to update_current (version #{@info2.lock_version}) a stale object: SpecCustomerInfo")
228
+ /Attempted to update_current \(version #{@info2.lock_version}\) a stale object: SpecCustomerInfo\./)
229
229
  end
230
230
 
231
231
  it "updates lock_version incrementally for each new record" do
232
232
  spec_customer_info = @customer.spec_customer_info
233
233
 
234
234
  expect {
235
- spec_customer_info.update_attributes(spec_person_name_id: 3)
235
+ spec_customer_info.update!(spec_person_name_id: 3)
236
236
  }.to change { spec_customer_info.lock_version }.from(0).to(1)
237
237
 
238
238
  expect {
239
- spec_customer_info.update_attributes(spec_person_name_id: 4)
239
+ spec_customer_info.update!(spec_person_name_id: 4)
240
240
  }.to change { spec_customer_info.lock_version }.from(1).to(2)
241
241
  end
242
242
 
243
243
  it "does not fail to update if a lock version growth is for any reason not monotonic" do
244
244
  spec_customer_info = @customer.spec_customer_info
245
245
 
246
- spec_customer_info.update_attributes(spec_person_name_id: 3)
247
- spec_customer_info.update_attributes(spec_person_name_id: 4)
246
+ spec_customer_info.update!(spec_person_name_id: 3)
247
+ spec_customer_info.update!(spec_person_name_id: 4)
248
248
 
249
249
  SpecCustomerInfo.where(spec_customer_id: @customer.id, lock_version: 1).delete_all
250
250
 
251
251
  expect {
252
- spec_customer_info.update_attributes(spec_person_name_id: 5)
252
+ spec_customer_info.update!(spec_person_name_id: 5)
253
253
  }.to change { spec_customer_info.lock_version }.from(2).to(3)
254
254
  end
255
255
 
256
256
  it "does not fail if no locking_column is present" do
257
257
  email = SpecCustomerEmail.create(spec_customer_id: 1, email: "foo@bar.com")
258
- expect{ email.update_attributes(email: "foo2@bar.com") }.not_to raise_error
258
+ expect{ email.update!(email: "foo2@bar.com") }.not_to raise_error
259
259
  end
260
260
 
261
261
  it "updates lock_version column based on parent relation" do
@@ -263,11 +263,11 @@ describe Moribus do
263
263
  spec_customer_info = @customer.spec_customer_info
264
264
 
265
265
  expect {
266
- spec_customer_info.update_attributes(spec_person_name_id: 3)
266
+ spec_customer_info.update!(spec_person_name_id: 3)
267
267
  }.to change { spec_customer_info.lock_version }.from(0).to(1)
268
268
 
269
269
  expect {
270
- spec_customer_info.update_attributes(spec_customer: @other_customer)
270
+ spec_customer_info.update!(spec_customer: @other_customer)
271
271
  }.to change { spec_customer_info.lock_version }.from(1).to(0)
272
272
  end
273
273
 
@@ -282,10 +282,10 @@ describe Moribus do
282
282
 
283
283
  expect( other_info_with_type.lock_version ).to eq 0
284
284
 
285
- info_with_type.update_attributes(spec_status: :active)
285
+ info_with_type.update!(spec_status: :active)
286
286
  expect( info_with_type.lock_version ).to eq 1
287
287
 
288
- info_with_type.update_attributes(spec_status: :inactive)
288
+ info_with_type.update!(spec_status: :inactive)
289
289
  expect( info_with_type.lock_version ).to eq 2
290
290
 
291
291
  expect( other_info_with_type.lock_version ).to eq 0
metadata CHANGED
@@ -1,38 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: HornsAndHooves-moribus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - HornsAndHooves
8
8
  - Arthur Shagall
9
9
  - Artem Kuzko
10
10
  - Sergey Potapov
11
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-10-14 00:00:00.000000000 Z
14
+ date: 2021-09-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
18
18
  requirement: !ruby/object:Gem::Requirement
19
19
  requirements:
20
- - - ">"
21
- - !ruby/object:Gem::Version
22
- version: '4.0'
23
- - - "<"
20
+ - - "~>"
24
21
  - !ruby/object:Gem::Version
25
- version: '5'
22
+ version: '6'
26
23
  type: :runtime
27
24
  prerelease: false
28
25
  version_requirements: !ruby/object:Gem::Requirement
29
26
  requirements:
30
- - - ">"
31
- - !ruby/object:Gem::Version
32
- version: '4.0'
33
- - - "<"
27
+ - - "~>"
34
28
  - !ruby/object:Gem::Version
35
- version: '5'
29
+ version: '6'
36
30
  - !ruby/object:Gem::Dependency
37
31
  name: power_enum
38
32
  requirement: !ruby/object:Gem::Requirement
@@ -107,16 +101,16 @@ dependencies:
107
101
  name: sqlite3
108
102
  requirement: !ruby/object:Gem::Requirement
109
103
  requirements:
110
- - - "~>"
104
+ - - ">="
111
105
  - !ruby/object:Gem::Version
112
- version: 1.3.6
106
+ version: '0'
113
107
  type: :development
114
108
  prerelease: false
115
109
  version_requirements: !ruby/object:Gem::Requirement
116
110
  requirements:
117
- - - "~>"
111
+ - - ">="
118
112
  - !ruby/object:Gem::Version
119
- version: 1.3.6
113
+ version: '0'
120
114
  description: |-
121
115
  Introduces Aggregated and Tracked behavior to ActiveRecord::Base models, as well
122
116
  as Macros and Extensions modules for more efficient usage.
@@ -153,6 +147,7 @@ files:
153
147
  - lib/moribus/version.rb
154
148
  - spec/dummy/README.rdoc
155
149
  - spec/dummy/Rakefile
150
+ - spec/dummy/app/assets/config/manifest.js
156
151
  - spec/dummy/app/assets/javascripts/application.js
157
152
  - spec/dummy/app/assets/stylesheets/application.css
158
153
  - spec/dummy/app/controllers/application_controller.rb
@@ -184,6 +179,7 @@ files:
184
179
  - spec/dummy/public/500.html
185
180
  - spec/dummy/public/favicon.ico
186
181
  - spec/dummy/script/rails
182
+ - spec/dummy/tmp/development_secret.txt
187
183
  - spec/moribus/aggregated_behavior_spec.rb
188
184
  - spec/moribus/alias_association_spec.rb
189
185
  - spec/moribus/extensions/delegate_associated_spec.rb
@@ -197,7 +193,7 @@ homepage: https://github.com/HornsAndHooves/moribus
197
193
  licenses:
198
194
  - MIT
199
195
  metadata: {}
200
- post_install_message:
196
+ post_install_message:
201
197
  rdoc_options: []
202
198
  require_paths:
203
199
  - lib
@@ -212,14 +208,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
208
  - !ruby/object:Gem::Version
213
209
  version: '0'
214
210
  requirements: []
215
- rubyforge_project:
216
- rubygems_version: 2.7.9
217
- signing_key:
211
+ rubygems_version: 3.0.3
212
+ signing_key:
218
213
  specification_version: 4
219
214
  summary: Introduces Aggregated and Tracked behavior to ActiveRecord::Base models
220
215
  test_files:
221
216
  - spec/dummy/README.rdoc
222
217
  - spec/dummy/Rakefile
218
+ - spec/dummy/app/assets/config/manifest.js
223
219
  - spec/dummy/app/assets/javascripts/application.js
224
220
  - spec/dummy/app/assets/stylesheets/application.css
225
221
  - spec/dummy/app/controllers/application_controller.rb
@@ -251,6 +247,7 @@ test_files:
251
247
  - spec/dummy/public/500.html
252
248
  - spec/dummy/public/favicon.ico
253
249
  - spec/dummy/script/rails
250
+ - spec/dummy/tmp/development_secret.txt
254
251
  - spec/moribus/aggregated_behavior_spec.rb
255
252
  - spec/moribus/alias_association_spec.rb
256
253
  - spec/moribus/extensions/delegate_associated_spec.rb