active_record-acts_as 4.0.0 → 5.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc594008886af5220c93ce7a44e2d7e5e2420b12d5930fc2d5387172fa0065b8
4
- data.tar.gz: 73b4f16970e323e9c266f7b7148068f99939efcfa12c323f08b23f4b3a4c63de
3
+ metadata.gz: fcf47ca7bac015adaa90752ec4f969cf677aba91247b244b92e53e5a426ea010
4
+ data.tar.gz: e91958fc1dfd1c54010cd8f3d472594d566cc18f1158e857c649cef7c5c8582a
5
5
  SHA512:
6
- metadata.gz: f4395d3cec20378b993702c59b88981549c1db17d14fc76231ceb936a2c85d445e22ce4898127268e3644aae4d29d580c8abe1792136fb670a1a4f4b7bc5ec3a
7
- data.tar.gz: 47188691e2f6e66dc6fbd6188594400efd2a05812d655c808c129b6055ed070f12ce16a2f88eeb425f81ca067a55664a3610a6a8ec3de838ed8576a87942ec58
6
+ metadata.gz: ead32dbcd66b63ffdda822a61b666b8451e70cb53f26a91bacf82ccadb1fef1bbc65db21e77d465b934041bd1bca5aabfcabb35c6245591173bcd7ed18b18b37
7
+ data.tar.gz: 8607d72f8937c4b183a9b1d27afffbdbde0055ab2af94138793fa4e7a0e10d8c59e4f0a518cdbfabde17e9a90d386d6912601ef79295dc6389034a5ba5be1162
@@ -1,13 +1,12 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  rvm:
4
- - 2.4
5
- - 2.5
6
4
  - 2.6
5
+ - 2.7
6
+ - 3.0
7
7
  before_install:
8
8
  - gem update --system
9
9
  gemfile:
10
- - gemfiles/rails_4.2.gemfile
11
- - gemfiles/rails_5.0.gemfile
12
- - gemfiles/rails_5.1.gemfile
13
- - gemfiles/rails_5.2.gemfile
10
+ - gemfiles/rails_6.0.gemfile
11
+ - gemfiles/rails_6.1.gemfile
12
+ - gemfiles/rails_master.gemfile
data/Appraisals CHANGED
@@ -1,15 +1,11 @@
1
- appraise 'rails-4.2' do
2
- gem 'rails', '~> 4.2.0'
1
+ appraise "rails-6.0" do
2
+ gem 'rails', '~> 6.0'
3
3
  end
4
4
 
5
- appraise 'rails-5.0' do
6
- gem 'rails', '~> 5.0.0'
5
+ appraise "rails-6.1" do
6
+ gem 'rails', '~> 6.1'
7
7
  end
8
8
 
9
- appraise 'rails-5.1' do
10
- gem 'rails', '~> 5.1.0'
11
- end
12
-
13
- appraise 'rails-5.2' do
14
- gem 'rails', '~> 5.2.0'
9
+ appraise "rails-master" do
10
+ gem 'rails', github: 'rails/rails'
15
11
  end
@@ -4,6 +4,44 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## [Unreleased] -
8
+
9
+ ## [5.0.0] - 2019-12-29 by @chaadow
10
+ ### Added
11
+ - Add support for rails 6 and 6.1 while removing rails 4.x and 5.x
12
+ from the travis matrix.
13
+ - Remove last ruby 3 warnings and make the gem **totally compatible with
14
+ ruby 3**
15
+ - Add support for rails master ( aka rails 6.2) to catch any upcoming
16
+ breaking change up front.
17
+ - bump minimum ruby version to 2.5
18
+ - Update test coverage
19
+
20
+ ### Fixed
21
+ - Fix `#touch` API to match rails 5/6 API and make it ruby 3 compatible
22
+ - collection methods such as `<<` work now under rails 6.1
23
+ - Prepare for Rails 6.2 breaking change by updating how errors
24
+ are accessed and removing warning. They are now ruby objects.
25
+ see [this](https://api.rubyonrails.org/v6.1.0/classes/ActiveModel/Errors.html)
26
+
27
+ ### Removed
28
+ - Remove support for rails 4.x and 5.x
29
+
30
+ ## [4.0.0] - 2019-01-09
31
+
32
+ ## [3.1.0] - 2018-12-13
33
+
34
+ ## [3.0.2] - 2018-08-12
35
+
36
+ ## [3.0.1] - 2018-04-25
37
+
38
+ ## [3.0.0] - 2019-02-21
39
+
40
+ ## [2.5.0] - 2017-07-29
41
+ ### Changed
42
+ - Drop support for Rails >= 5.0
43
+ - Remove warnings occurring in Rails 5.1
44
+
7
45
  ## [2.4.2] - 2017-04-20
8
46
  ### Fixed
9
47
  - Fix querying for conditions with hashes.
@@ -22,10 +60,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
22
60
 
23
61
  ## [2.3.0] - 2017-04-12
24
62
  ### Fixed
25
- - Prevent duplicate validation errors (fixes https://github.com/krautcomputing/active_record-acts_as/issues/2)
63
+ - Prevent duplicate validation errors (fixes https://github.com/chaadow/active_record-acts_as/issues/2)
26
64
 
27
65
  ### Added
28
- - Added support for touching submodel attributes (https://github.com/krautcomputing/active_record-acts_as/pull/3, thanks to [dezmathio](https://github.com/dezmathio)!)
66
+ - Added support for touching submodel attributes (https://github.com/chaadow/active_record-acts_as/pull/3, thanks to [dezmathio](https://github.com/dezmathio)!)
29
67
 
30
68
  ## [2.2.1] - 2017-04-08
31
69
  ### Fixed
@@ -92,33 +130,39 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
92
130
  ### Fixed
93
131
  - Fixed `remove_actable` migration helper (https://github.com/hzamani/active_record-acts_as/pull/71, thanks to [nuclearpidgeon](https://github.com/nuclearpidgeon)!)
94
132
 
95
- [Unreleased]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.4.2...HEAD
96
- [2.4.2]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.4.1...v2.4.2
97
- [2.4.1]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.4.0...v2.4.1
98
- [2.4.0]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.3.1...v2.4.0
99
- [2.3.1]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.3.0...v2.3.1
100
- [2.3.0]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.2.1...v2.3.0
101
- [2.2.1]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.2.0...v2.2.1
102
- [2.2.0]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.1.1...v2.2.0
103
- [2.1.1]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.1.0...v2.1.1
104
- [2.1.0]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.0.9...v2.1.0
105
- [2.0.9]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.0.8...v2.0.9
106
- [2.0.8]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.0.7...v2.0.8
107
- [2.0.7]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.0.6...v2.0.7
108
- [2.0.6]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.0.5...v2.0.6
109
- [2.0.5]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.0.4...v2.0.5
110
- [2.0.4]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.0.3...v2.0.4
111
- [2.0.3]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.0.2...v2.0.3
112
- [2.0.2]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.0.1...v2.0.2
113
- [2.0.1]: https://github.com/krautcomputing/active_record-acts_as/compare/v2.0.0...v2.0.1
114
- [2.0.0]: https://github.com/krautcomputing/active_record-acts_as/compare/v1.0.8...v2.0.0
115
- [1.0.8]: https://github.com/krautcomputing/active_record-acts_as/compare/v1.0.7...v1.0.8
116
- [1.0.7]: https://github.com/krautcomputing/active_record-acts_as/compare/v1.0.6...v1.0.7
117
- [1.0.6]: https://github.com/krautcomputing/active_record-acts_as/compare/v1.0.5...v1.0.6
118
- [1.0.5]: https://github.com/krautcomputing/active_record-acts_as/compare/v1.0.4...v1.0.5
119
- [1.0.4]: https://github.com/krautcomputing/active_record-acts_as/compare/v1.0.3...v1.0.4
120
- [1.0.3]: https://github.com/krautcomputing/active_record-acts_as/compare/v1.0.2...v1.0.3
121
- [1.0.2]: https://github.com/krautcomputing/active_record-acts_as/compare/v1.0.1...v1.0.2
122
- [1.0.1]: https://github.com/krautcomputing/active_record-acts_as/compare/v1.0.0...v1.0.1
123
- [1.0.0]: https://github.com/krautcomputing/active_record-acts_as/compare/v1.0.0.rc...v1.0.0
124
- [1.0.0.rc]: https://github.com/krautcomputing/active_record-acts_as/compare/v1.0.0.pre...v1.0.0.rc
133
+ [Unreleased]: https://github.com/chaadow/active_record-acts_as/compare/v5.0.0...HEAD
134
+ [5.0.0]: https://github.com/chaadow/active_record-acts_as/compare/v4.0.0...v5.0.0
135
+ [3.1.0]: https://github.com/chaadow/active_record-acts_as/compare/v3.1.0...v4.0.0
136
+ [3.0.2]: https://github.com/chaadow/active_record-acts_as/compare/v3.0.1...v3.0.2
137
+ [3.0.1]: https://github.com/chaadow/active_record-acts_as/compare/v3.0.0...v3.0.1
138
+ [3.0.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.5.0...v3.0.0
139
+ [2.5.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.4.2...v2.5.0
140
+ [2.4.2]: https://github.com/chaadow/active_record-acts_as/compare/v2.4.1...v2.4.2
141
+ [2.4.1]: https://github.com/chaadow/active_record-acts_as/compare/v2.4.0...v2.4.1
142
+ [2.4.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.3.1...v2.4.0
143
+ [2.3.1]: https://github.com/chaadow/active_record-acts_as/compare/v2.3.0...v2.3.1
144
+ [2.3.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.2.1...v2.3.0
145
+ [2.2.1]: https://github.com/chaadow/active_record-acts_as/compare/v2.2.0...v2.2.1
146
+ [2.2.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.1.1...v2.2.0
147
+ [2.1.1]: https://github.com/chaadow/active_record-acts_as/compare/v2.1.0...v2.1.1
148
+ [2.1.0]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.9...v2.1.0
149
+ [2.0.9]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.8...v2.0.9
150
+ [2.0.8]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.7...v2.0.8
151
+ [2.0.7]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.6...v2.0.7
152
+ [2.0.6]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.5...v2.0.6
153
+ [2.0.5]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.4...v2.0.5
154
+ [2.0.4]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.3...v2.0.4
155
+ [2.0.3]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.2...v2.0.3
156
+ [2.0.2]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.1...v2.0.2
157
+ [2.0.1]: https://github.com/chaadow/active_record-acts_as/compare/v2.0.0...v2.0.1
158
+ [2.0.0]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.8...v2.0.0
159
+ [1.0.8]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.7...v1.0.8
160
+ [1.0.7]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.6...v1.0.7
161
+ [1.0.6]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.5...v1.0.6
162
+ [1.0.5]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.4...v1.0.5
163
+ [1.0.4]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.3...v1.0.4
164
+ [1.0.3]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.2...v1.0.3
165
+ [1.0.2]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.1...v1.0.2
166
+ [1.0.1]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.0...v1.0.1
167
+ [1.0.0]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.0.rc...v1.0.0
168
+ [1.0.0.rc]: https://github.com/chaadow/active_record-acts_as/compare/v1.0.0.pre...v1.0.0.rc
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/active_record-acts_as.svg)](http://badge.fury.io/rb/active_record-acts_as)
2
- [![Build Status](https://travis-ci.org/krautcomputing/active_record-acts_as.svg)](https://travis-ci.org/krautcomputing/active_record-acts_as)
3
- [![Code Climate](https://codeclimate.com/github/krautcomputing/active_record-acts_as.png)](https://codeclimate.com/github/krautcomputing/active_record-acts_as)
4
- [![Coverage Status](https://coveralls.io/repos/krautcomputing/active_record-acts_as/badge.png)](https://coveralls.io/r/krautcomputing/active_record-acts_as)
2
+ [![Build Status](https://travis-ci.org/chaadow/active_record-acts_as.svg)](https://travis-ci.org/chaadow/active_record-acts_as)
5
3
 
6
4
  # ActiveRecord::ActsAs
7
5
 
@@ -20,9 +18,11 @@ a separate table for each product type, i.e. a `pens` table with `color` column.
20
18
 
21
19
  ## Requirements
22
20
 
23
- * Ruby >= 2.4
24
- * ActiveSupport >= 4.2
25
- * ActiveRecord >= 4.2
21
+ * Ruby >= `2.5`
22
+ * ActiveSupport >= `6.0`
23
+ * ActiveRecord >= `6.0`
24
+ * Regarding ActiveRecord `5.2.x` please use version `4.0.3` of this gem. If you encounter any bug you can open an issue.
25
+ Maintenance will be stopped after the release of ActiveRecord `6.2`
26
26
 
27
27
  ## Installation
28
28
 
@@ -219,7 +219,7 @@ end
219
219
 
220
220
  ## Contributing
221
221
 
222
- 1. Fork it ( https://github.com/krautcomputing/active_record-acts_as/fork )
222
+ 1. Fork it (https://github.com/chaadow/active_record-acts_as/fork)
223
223
  2. Create your feature branch (`git checkout -b my-new-feature`)
224
224
  3. Test changes don't break anything (`rspec`)
225
225
  4. Add specs for your new feature
@@ -6,11 +6,11 @@ require 'active_record/acts_as/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "active_record-acts_as"
8
8
  spec.version = ActiveRecord::ActsAs::VERSION
9
- spec.authors = ["Hassan Zamani", "Manuel Meurer"]
10
- spec.email = ["hsn.zamani@gmail.com", "manuel@krautcomputing.com"]
9
+ spec.authors = ["Hassan Zamani", "Manuel Meurer", "Chedli Bourguiba"]
10
+ spec.email = ["hsn.zamani@gmail.com", "manuel@krautcomputing.com", "bourguiba.chedli@gmail.com"]
11
11
  spec.summary = %q{Simulate multi-table inheritance for activerecord models}
12
12
  spec.description = %q{Simulate multi-table inheritance for activerecord models using a polymorphic association}
13
- spec.homepage = "http://github.com/krautcomputing/active_record-acts_as"
13
+ spec.homepage = "http://github.com/chaadow/active_record-acts_as"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -18,15 +18,16 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.required_ruby_version = ">= 2.4"
21
+ spec.required_ruby_version = ">= 2.5"
22
22
 
23
- spec.add_development_dependency "sqlite3", "~> 1.3"
23
+ spec.add_development_dependency "sqlite3"
24
24
  spec.add_development_dependency "bundler"
25
25
  spec.add_development_dependency "rspec", "~> 3"
26
26
  spec.add_development_dependency "rake", "~> 10"
27
27
  spec.add_development_dependency "appraisal", "~> 2.1"
28
28
  spec.add_development_dependency "guard-rspec", "~> 4.7"
29
29
 
30
- spec.add_dependency "activesupport", ">= 4.2"
31
- spec.add_dependency "activerecord", ">= 4.2"
30
+ spec.add_dependency "activesupport", ">= 6.0"
31
+ spec.add_dependency "activerecord", ">= 6.0"
32
+
32
33
  end
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "coveralls", require: false
6
- gem "rails", "~> 4.2.0"
6
+ gem "rails", "~> 6.0.0"
7
7
 
8
8
  gemspec path: "../"
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "coveralls", require: false
6
- gem "rails", "~> 5.0.0"
6
+ gem "rails", "~> 6.1.0"
7
7
 
8
8
  gemspec path: "../"
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "coveralls", require: false
6
- gem "rails", "~> 5.1.0"
6
+ gem "rails", github: 'rails'
7
7
 
8
8
  gemspec path: "../"
@@ -19,8 +19,10 @@ module ActiveRecord
19
19
 
20
20
  def actable_must_be_valid
21
21
  unless acting_as.valid?
22
- acting_as.errors.each do |attribute, message|
23
- errors.add(attribute, message) unless errors[attribute].include?(message)
22
+ acting_as.errors.messages.each do |attribute, messages|
23
+ messages.each do |message|
24
+ errors.add(attribute, message) unless errors[attribute].include?(message)
25
+ end
24
26
  end
25
27
  end
26
28
  end
@@ -42,6 +44,14 @@ module ActiveRecord
42
44
  end
43
45
  end
44
46
 
47
+ def _write_attribute(attr_name, value, *args, &block)
48
+ if attribute_method?(attr_name.to_s)
49
+ super
50
+ else
51
+ acting_as.send(:_write_attribute, attr_name, value, *args, &block)
52
+ end
53
+ end
54
+
45
55
  def read_store_attribute(store_attribute, key)
46
56
  if attribute_method?(store_attribute.to_s)
47
57
  super
@@ -83,10 +93,10 @@ module ActiveRecord
83
93
  end
84
94
  end
85
95
 
86
- def touch(*args)
96
+ def touch(*args, time: nil)
87
97
  self_args, acting_as_args = args.partition { |arg| has_attribute?(arg, true) }
88
- super(*self_args) if self_args.any?
89
- acting_as.touch(*acting_as_args) if acting_as.persisted?
98
+ super(*self_args, time: time) if self_args.any?
99
+ acting_as.touch(*acting_as_args, time: time) if acting_as.persisted?
90
100
  end
91
101
 
92
102
  def respond_to?(name, include_private = false, as_original_class = false)
@@ -2,20 +2,20 @@ module ActiveRecord
2
2
  module ActsAs
3
3
  module Migration
4
4
  module TableDefinition
5
- def actable(options = {})
5
+ def actable(**options)
6
6
  name = options.delete(:as) || :actable
7
7
  options[:polymorphic] = true
8
- references(name, options)
8
+ references(name, **options)
9
9
  end
10
10
  end
11
11
 
12
12
  module Table
13
13
  include TableDefinition
14
14
 
15
- def remove_actable(options = {})
15
+ def remove_actable(**options)
16
16
  name = options.delete(:as) || :actable
17
17
  options[:polymorphic] = true
18
- @base.remove_reference(@name, name, options)
18
+ @base.remove_reference(@name, name, **options)
19
19
  end
20
20
  end
21
21
  end
@@ -28,8 +28,11 @@ module ActiveRecord
28
28
 
29
29
  module ScopeForCreate
30
30
  def scope_for_create(attributes = nil)
31
+ return super() unless acting_as?
32
+
31
33
  scope = respond_to?(:values_for_create) ? values_for_create(attributes) : where_values_hash
32
- scope.merge!(where_values_hash(acting_as_model.table_name)) if acting_as?
34
+ scope.merge!(where_values_hash(acting_as_model.table_name))
35
+ scope.merge!(attributes) if attributes
33
36
  scope.merge(create_with_value)
34
37
  end
35
38
  end
@@ -14,7 +14,7 @@ module ActiveRecord
14
14
 
15
15
  options = options.reverse_merge(as: as, validate: false, autosave: true, inverse_of: as)
16
16
 
17
- reflections = has_one(name, scope, options)
17
+ reflections = has_one(name, scope, **options)
18
18
  default_scope -> {
19
19
  case association_method
20
20
  when :eager_load
@@ -28,11 +28,11 @@ module ActiveRecord
28
28
  validate :actable_must_be_valid if validates_actable
29
29
 
30
30
  unless touch == false
31
- after_update :touch, if: ActiveRecord.version.to_s.to_f >= 5.1 ? :saved_changes? : :changed?
31
+ after_update :touch, if: :saved_changes?
32
32
  end
33
33
 
34
34
  before_save do
35
- @_acting_as_changed = ActiveRecord.version.to_s.to_f >= 5.1 ? acting_as.has_changes_to_save? : acting_as.changed?
35
+ @_acting_as_changed = acting_as.has_changes_to_save?
36
36
  true
37
37
  end
38
38
  after_commit do
@@ -79,11 +79,11 @@ module ActiveRecord
79
79
  def actable(scope = nil, **options)
80
80
  name = options.delete(:as) || :actable
81
81
 
82
- reflections = belongs_to(name, scope, options.reverse_merge(validate: false,
83
- polymorphic: true,
84
- dependent: :destroy,
85
- autosave: true,
86
- inverse_of: to_s.underscore))
82
+ reflections = belongs_to(name, scope, **options.reverse_merge(validate: false,
83
+ polymorphic: true,
84
+ dependent: :destroy,
85
+ autosave: true,
86
+ inverse_of: to_s.underscore))
87
87
 
88
88
  cattr_reader(:actable_reflection) { reflections.stringify_keys[name.to_s] }
89
89
 
@@ -1,6 +1,6 @@
1
1
  module ActiveRecord
2
2
  module ActsAs
3
- VERSION = "4.0.0"
3
+ VERSION = "5.0.1"
4
4
  end
5
5
  end
6
6
 
@@ -221,10 +221,11 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
221
221
 
222
222
  context 'touching' do
223
223
  describe '#touch with arguments' do
224
- it "forwards supermodel arguments tothe supermodel" do
224
+ it "forwards supermodel arguments to the supermodel" do
225
+ now = Time.current
225
226
  pen.save!
226
- expect(pen.product).to receive(:touch).with(:updated_at)
227
- pen.touch(:updated_at, :designed_at)
227
+ expect(pen.product).to receive(:touch).with(:updated_at, {time: now})
228
+ pen.touch(:updated_at, time: now)
228
229
  end
229
230
 
230
231
  it "updates submodel arguments" do
@@ -236,7 +237,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
236
237
  describe '#touch without arguments' do
237
238
  it "touches the supermodel" do
238
239
  pen.save!
239
- expect(pen.product).to receive(:touch).with(no_args)
240
+ expect(pen.product).to receive(:touch).with(time: nil)
240
241
  pen.touch
241
242
  end
242
243
  end
@@ -299,21 +300,21 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
299
300
  it "combines supermodel and submodel errors" do
300
301
  pen = Pen.new
301
302
  expect(pen).to be_invalid
302
- expect(pen.errors.to_h).to eq(
303
- name: "can't be blank",
304
- price: "can't be blank",
305
- color: "can't be blank"
303
+ expect(pen.errors.to_hash).to eq(
304
+ name: ["can't be blank"],
305
+ price: ["can't be blank"],
306
+ color: ["can't be blank"]
306
307
  )
307
308
  pen.name = 'testing'
308
309
  expect(pen).to be_invalid
309
- expect(pen.errors.to_h).to eq(
310
- price: "can't be blank",
311
- color: "can't be blank"
310
+ expect(pen.errors.to_hash).to eq(
311
+ price: ["can't be blank"],
312
+ color: ["can't be blank"]
312
313
  )
313
314
  pen.color = 'red'
314
315
  expect(pen).to be_invalid
315
- expect(pen.errors.to_h).to eq(
316
- price: "can't be blank"
316
+ expect(pen.errors.to_hash).to eq(
317
+ price: ["can't be blank"]
317
318
  )
318
319
  pen.price = 0.8
319
320
  expect(pen).to be_valid
@@ -324,8 +325,8 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
324
325
  it "unless validates_actable is set to false" do
325
326
  pen = IsolatedPen.new
326
327
  expect(pen).to be_invalid
327
- expect(pen.errors.to_h).to eq(
328
- color: "can't be blank"
328
+ expect(pen.errors.to_hash).to eq(
329
+ color: ["can't be blank"]
329
330
  )
330
331
  pen.color = 'red'
331
332
  expect(pen).to be_valid
@@ -402,7 +403,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
402
403
  it "returns a query for the actable records" do
403
404
  red_pen = Pen.create!(name: 'red pen', price: 0.8, color: 'red')
404
405
  blue_pen = Pen.create!(name: 'blue pen', price: 0.8, color: 'blue')
405
- black_pen = Pen.create!(name: 'black pen', price: 0.9, color: 'black')
406
+ _black_pen = Pen.create!(name: 'black pen', price: 0.9, color: 'black')
406
407
 
407
408
  actables = Pen.where(price: 0.8).actables
408
409
 
@@ -438,7 +439,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
438
439
 
439
440
  context 'when they are defined via `scope`' do
440
441
  it 'can be called from the submodel' do
441
- cheap_pen = Pen.create!(name: 'cheap pen', price: 0.5, color: 'blue')
442
+ _cheap_pen = Pen.create!(name: 'cheap pen', price: 0.5, color: 'blue')
442
443
  expensive_pen = Pen.create!(name: 'expensive pen', price: 1, color: 'red')
443
444
 
444
445
  expect(Product.with_price_higher_than(0.5).to_a).to eq([expensive_pen.acting_as])
@@ -528,6 +529,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
528
529
  describe '.scope_for_create' do
529
530
  it 'includes supermodel attributes' do
530
531
  relation = Pen.where(name: 'new name', price: 1.4, color: 'red')
532
+
531
533
  expect(relation.scope_for_create).to include('name')
532
534
  expect(relation.scope_for_create['name']).to eq('new name')
533
535
  end
@@ -562,7 +564,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
562
564
  Object.send(:remove_const, :Pen)
563
565
  end
564
566
 
565
- it "should not include the selected attribute when associating using 'eager_load'" do
567
+ it "should include the selected attribute when associating using 'eager_load'" do
566
568
  class Pen < ActiveRecord::Base
567
569
  acts_as :product , {association_method: :eager_load}
568
570
  store_accessor :settings, :option1
@@ -570,7 +572,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
570
572
  end
571
573
  Pen.create pen_attributes
572
574
 
573
- expect(Pen.select("'something' as thing").first['thing']).to be_nil
575
+ expect(Pen.select("'something' as thing").first['thing']).to eq 'something'
574
576
  end
575
577
 
576
578
  it "should include the selected attribute in the model when associating using 'includes'" do
@@ -0,0 +1,23 @@
1
+ require 'models'
2
+
3
+ RSpec.describe 'Model Initialization' do
4
+ subject { Pen }
5
+
6
+ let(:pen_attributes) { { name: 'pen', color: 'red' } }
7
+
8
+ before(:each) { clear_database }
9
+
10
+ it 'find_or_initialize_by works' do
11
+ pen = subject.find_or_initialize_by(pen_attributes)
12
+ expect(pen.persisted?).to be false
13
+ expect(pen.name).to eq(pen_attributes[:name])
14
+ expect(pen.color).to eq(pen_attributes[:color])
15
+ end
16
+
17
+ it 'where.first_or_initialize works' do
18
+ pen = subject.where(pen_attributes).first_or_initialize
19
+ expect(pen.persisted?).to be false
20
+ expect(pen.name).to eq(pen_attributes[:name])
21
+ expect(pen.color).to eq(pen_attributes[:color])
22
+ end
23
+ end
metadata CHANGED
@@ -1,30 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-acts_as
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hassan Zamani
8
8
  - Manuel Meurer
9
- autorequire:
9
+ - Chedli Bourguiba
10
+ autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2019-01-09 00:00:00.000000000 Z
13
+ date: 2021-01-28 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: sqlite3
16
17
  requirement: !ruby/object:Gem::Requirement
17
18
  requirements:
18
- - - "~>"
19
+ - - ">="
19
20
  - !ruby/object:Gem::Version
20
- version: '1.3'
21
+ version: '0'
21
22
  type: :development
22
23
  prerelease: false
23
24
  version_requirements: !ruby/object:Gem::Requirement
24
25
  requirements:
25
- - - "~>"
26
+ - - ">="
26
27
  - !ruby/object:Gem::Version
27
- version: '1.3'
28
+ version: '0'
28
29
  - !ruby/object:Gem::Dependency
29
30
  name: bundler
30
31
  requirement: !ruby/object:Gem::Requirement
@@ -101,33 +102,34 @@ dependencies:
101
102
  requirements:
102
103
  - - ">="
103
104
  - !ruby/object:Gem::Version
104
- version: '4.2'
105
+ version: '6.0'
105
106
  type: :runtime
106
107
  prerelease: false
107
108
  version_requirements: !ruby/object:Gem::Requirement
108
109
  requirements:
109
110
  - - ">="
110
111
  - !ruby/object:Gem::Version
111
- version: '4.2'
112
+ version: '6.0'
112
113
  - !ruby/object:Gem::Dependency
113
114
  name: activerecord
114
115
  requirement: !ruby/object:Gem::Requirement
115
116
  requirements:
116
117
  - - ">="
117
118
  - !ruby/object:Gem::Version
118
- version: '4.2'
119
+ version: '6.0'
119
120
  type: :runtime
120
121
  prerelease: false
121
122
  version_requirements: !ruby/object:Gem::Requirement
122
123
  requirements:
123
124
  - - ">="
124
125
  - !ruby/object:Gem::Version
125
- version: '4.2'
126
+ version: '6.0'
126
127
  description: Simulate multi-table inheritance for activerecord models using a polymorphic
127
128
  association
128
129
  email:
129
130
  - hsn.zamani@gmail.com
130
131
  - manuel@krautcomputing.com
132
+ - bourguiba.chedli@gmail.com
131
133
  executables:
132
134
  - console
133
135
  extensions: []
@@ -146,10 +148,9 @@ files:
146
148
  - _config.yml
147
149
  - active_record-acts_as.gemspec
148
150
  - bin/console
149
- - gemfiles/rails_4.2.gemfile
150
- - gemfiles/rails_5.0.gemfile
151
- - gemfiles/rails_5.1.gemfile
152
- - gemfiles/rails_5.2.gemfile
151
+ - gemfiles/rails_6.0.gemfile
152
+ - gemfiles/rails_6.1.gemfile
153
+ - gemfiles/rails_master.gemfile
153
154
  - lib/active_record/acts_as.rb
154
155
  - lib/active_record/acts_as/class_methods.rb
155
156
  - lib/active_record/acts_as/instance_methods.rb
@@ -162,15 +163,16 @@ files:
162
163
  - spec/active_record_spec.rb
163
164
  - spec/acts_as_spec.rb
164
165
  - spec/database_helper.rb
166
+ - spec/find_or_initialize_by_spec.rb
165
167
  - spec/migrations_spec.rb
166
168
  - spec/models.rb
167
169
  - spec/rspec_matchers_spec.rb
168
170
  - spec/spec_helper.rb
169
- homepage: http://github.com/krautcomputing/active_record-acts_as
171
+ homepage: http://github.com/chaadow/active_record-acts_as
170
172
  licenses:
171
173
  - MIT
172
174
  metadata: {}
173
- post_install_message:
175
+ post_install_message:
174
176
  rdoc_options: []
175
177
  require_paths:
176
178
  - lib
@@ -178,15 +180,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
178
180
  requirements:
179
181
  - - ">="
180
182
  - !ruby/object:Gem::Version
181
- version: '2.4'
183
+ version: '2.5'
182
184
  required_rubygems_version: !ruby/object:Gem::Requirement
183
185
  requirements:
184
186
  - - ">="
185
187
  - !ruby/object:Gem::Version
186
188
  version: '0'
187
189
  requirements: []
188
- rubygems_version: 3.0.2
189
- signing_key:
190
+ rubygems_version: 3.2.3
191
+ signing_key:
190
192
  specification_version: 4
191
193
  summary: Simulate multi-table inheritance for activerecord models
192
194
  test_files:
@@ -194,6 +196,7 @@ test_files:
194
196
  - spec/active_record_spec.rb
195
197
  - spec/acts_as_spec.rb
196
198
  - spec/database_helper.rb
199
+ - spec/find_or_initialize_by_spec.rb
197
200
  - spec/migrations_spec.rb
198
201
  - spec/models.rb
199
202
  - spec/rspec_matchers_spec.rb
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "coveralls", require: false
6
- gem "rails", "~> 5.2.0"
7
-
8
- gemspec path: "../"