HornsAndHooves-moribus 0.6.0 → 0.7.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: 0d973c4c4d01859f5d577ec5c594b78d36c5e6064885b843804a984670d6e2c4
4
+ data.tar.gz: b7a269f5cc0bb99e3833d219f593e726b98be3371904cfe7d1deb16a45af1ee0
5
5
  SHA512:
6
- metadata.gz: 5af699607d6d67710af3e538cc23138b0a934236c5ce2b234ebc9a3349f989c6e7eaa1184a9608d5b3f77e5ff2898d2f96757d5805d39e7a1d4af349947cbef3
7
- data.tar.gz: 7a8cec103bc680b45800f888adfda114b7cbe55d3ef5547694f2227cd79afff4f2e3b503782ae79b84f8beab7a80b6c0452369d464c8c8a9daf01e9c3c8335b3
6
+ metadata.gz: e193850f47dabd551af7e4cf31ef9b4e92653151533fc4190b8aa2fb0b2a74142c606b7de75821a273a53040402e1cfad9a1498e019cd45bf4886834baf4e3ec
7
+ data.tar.gz: e575f9663606d2367b594537a4cbd9222cbe44c36e0386dd6bf40378ba3ec39d66f2e626b0f1914a24850238254ded9905957775ecb1821d99b48a08d8b446e6
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,7 +20,7 @@ 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", "~> 5.0"
24
24
  s.add_dependency "power_enum", ">= 2.7.0"
25
25
  s.add_dependency "yard", ">= 0"
26
26
 
@@ -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.7.0" # :nodoc:
3
3
  end
@@ -0,0 +1 @@
1
+ 02c924139ba4207bce788dd378b8f1f99976099325bbad4e85204e34d04970e039409db0f08ceea070238f4f5a41bdbc94fb6e51aeb0996a4ee32bcd3c31ede1
@@ -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
@@ -225,7 +225,7 @@ describe Moribus do
225
225
 
226
226
  expect{ @info2.update_attributes(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
metadata CHANGED
@@ -1,7 +1,7 @@
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.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - HornsAndHooves
@@ -11,28 +11,22 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-10-14 00:00:00.000000000 Z
14
+ date: 2019-10-18 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: '5.0'
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: '5.0'
36
30
  - !ruby/object:Gem::Dependency
37
31
  name: power_enum
38
32
  requirement: !ruby/object:Gem::Requirement
@@ -184,6 +178,7 @@ files:
184
178
  - spec/dummy/public/500.html
185
179
  - spec/dummy/public/favicon.ico
186
180
  - spec/dummy/script/rails
181
+ - spec/dummy/tmp/development_secret.txt
187
182
  - spec/moribus/aggregated_behavior_spec.rb
188
183
  - spec/moribus/alias_association_spec.rb
189
184
  - spec/moribus/extensions/delegate_associated_spec.rb
@@ -251,6 +246,7 @@ test_files:
251
246
  - spec/dummy/public/500.html
252
247
  - spec/dummy/public/favicon.ico
253
248
  - spec/dummy/script/rails
249
+ - spec/dummy/tmp/development_secret.txt
254
250
  - spec/moribus/aggregated_behavior_spec.rb
255
251
  - spec/moribus/alias_association_spec.rb
256
252
  - spec/moribus/extensions/delegate_associated_spec.rb