active_record-acts_as 3.1.0 → 5.0.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: bbfc7ea492327e566ab788c73aeb7d294a9d9b4f66049464c9bdcdd5e293bd2a
4
- data.tar.gz: f9142f0468e292d87c4d0637970ca49823cc44664eb59fe09e975d3fe887fc04
3
+ metadata.gz: 5bfaa5ca9169073f3896b1aeb86e905e604630d82c41a94ab3686f32da5b6dd7
4
+ data.tar.gz: e7be68ef37b33ff53696b87fa340ba7cd824219907db046f0be8b34631c7b3af
5
5
  SHA512:
6
- metadata.gz: a1ac325e5b476330009606cad7248eb51c62ef8e5bf55ea1ac3ed099e55392716a7aceed1b0f6078a3031f4ab29ddcd86fd634c490289c41ff293381609fc68f
7
- data.tar.gz: 3aaaf59d5b1b229bcedefb4135ba16df442016680096071c1ce6de076293158e803cc670ecda0f67ab991a4ee4a9112db44e63f757004cc759f17102deead977
6
+ metadata.gz: 340035e0b4f8d725a9789e59c54f104c154dc3a142a3e0ba3e32d70ecf7742dfebb5fd8027360451f3e0b63295014ddc231f38d61e7b6e599ece65f39ae4cb19
7
+ data.tar.gz: 7c0ec150bc1d2a64eb2831208919b146f51a35c8397fbf3cd5069353e0ae67f41d28be2afd7da9268f4d65c1489a505d311791c0af037425370d77efbbbc20f7
@@ -1,14 +1,12 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  rvm:
4
- - 2.2.7
5
- - 2.3.4
6
- - 2.4.1
4
+ - 2.6
5
+ - 2.7
6
+ - 3.0
7
7
  before_install:
8
8
  - gem update --system
9
- - gem update bundler
10
9
  gemfile:
11
- - gemfiles/rails_4.2.gemfile
12
- - gemfiles/rails_5.0.gemfile
13
- - gemfiles/rails_5.1.gemfile
14
- - 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.rc1'
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,8 +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)
5
- [![Dependency Status](https://gemnasium.com/krautcomputing/active_record-acts_as.svg)](https://gemnasium.com/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)
6
3
 
7
4
  # ActiveRecord::ActsAs
8
5
 
@@ -21,9 +18,11 @@ a separate table for each product type, i.e. a `pens` table with `color` column.
21
18
 
22
19
  ## Requirements
23
20
 
24
- * Ruby >= 2.2
25
- * ActiveSupport >= 4.2
26
- * 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`
27
26
 
28
27
  ## Installation
29
28
 
@@ -220,7 +219,7 @@ end
220
219
 
221
220
  ## Contributing
222
221
 
223
- 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)
224
223
  2. Create your feature branch (`git checkout -b my-new-feature`)
225
224
  3. Test changes don't break anything (`rspec`)
226
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.2"
21
+ spec.required_ruby_version = ">= 2.5"
22
22
 
23
- spec.add_development_dependency "sqlite3", "~> 1.3"
24
- spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "sqlite3"
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", "< 5.2.2.rc1"
31
- spec.add_dependency "activerecord", ">= 4.2", "< 5.2.2.rc1"
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"
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"
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", git: 'https://github.com/rails/rails.git'
7
7
 
8
8
  gemspec path: "../"
@@ -19,8 +19,8 @@ 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.each do |error|
23
+ errors.add(error.attribute, error.message) unless errors[error.attribute].include?(error.message)
24
24
  end
25
25
  end
26
26
  end
@@ -42,6 +42,14 @@ module ActiveRecord
42
42
  end
43
43
  end
44
44
 
45
+ def _write_attribute(attr_name, value, *args, &block)
46
+ if attribute_method?(attr_name.to_s)
47
+ super
48
+ else
49
+ acting_as.send(:_write_attribute, attr_name, value, *args, &block)
50
+ end
51
+ end
52
+
45
53
  def read_store_attribute(store_attribute, key)
46
54
  if attribute_method?(store_attribute.to_s)
47
55
  super
@@ -83,10 +91,10 @@ module ActiveRecord
83
91
  end
84
92
  end
85
93
 
86
- def touch(*args)
94
+ def touch(*args, time: nil)
87
95
  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?
96
+ super(*self_args, time: time) if self_args.any?
97
+ acting_as.touch(*acting_as_args, time: time) if acting_as.persisted?
90
98
  end
91
99
 
92
100
  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,10 +28,11 @@ module ActiveRecord
28
28
 
29
29
  module ScopeForCreate
30
30
  def scope_for_create(attributes = nil)
31
- scope = ActiveRecord.version.to_s.to_f >= 5.2 ? super(attributes) : where_values_hash
32
- if acting_as?
33
- scope.merge!(where_values_hash(acting_as_model.table_name))
34
- end
31
+ return super() unless acting_as?
32
+
33
+ scope = respond_to?(:values_for_create) ? values_for_create(attributes) : where_values_hash
34
+ scope.merge!(where_values_hash(acting_as_model.table_name))
35
+ scope.merge!(attributes) if attributes
35
36
  scope.merge(create_with_value)
36
37
  end
37
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 = "3.1.0"
3
+ VERSION = "5.0.0"
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,44 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-acts_as
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 5.0.0
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: 2018-12-13 00:00:00.000000000 Z
13
+ date: 2020-12-29 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
31
32
  requirements:
32
- - - "~>"
33
+ - - ">="
33
34
  - !ruby/object:Gem::Version
34
- version: '1.6'
35
+ version: '0'
35
36
  type: :development
36
37
  prerelease: false
37
38
  version_requirements: !ruby/object:Gem::Requirement
38
39
  requirements:
39
- - - "~>"
40
+ - - ">="
40
41
  - !ruby/object:Gem::Version
41
- version: '1.6'
42
+ version: '0'
42
43
  - !ruby/object:Gem::Dependency
43
44
  name: rspec
44
45
  requirement: !ruby/object:Gem::Requirement
@@ -101,45 +102,34 @@ dependencies:
101
102
  requirements:
102
103
  - - ">="
103
104
  - !ruby/object:Gem::Version
104
- version: '4.2'
105
- - - "<"
106
- - !ruby/object:Gem::Version
107
- version: 5.2.2.rc1
105
+ version: '6.0'
108
106
  type: :runtime
109
107
  prerelease: false
110
108
  version_requirements: !ruby/object:Gem::Requirement
111
109
  requirements:
112
110
  - - ">="
113
111
  - !ruby/object:Gem::Version
114
- version: '4.2'
115
- - - "<"
116
- - !ruby/object:Gem::Version
117
- version: 5.2.2.rc1
112
+ version: '6.0'
118
113
  - !ruby/object:Gem::Dependency
119
114
  name: activerecord
120
115
  requirement: !ruby/object:Gem::Requirement
121
116
  requirements:
122
117
  - - ">="
123
118
  - !ruby/object:Gem::Version
124
- version: '4.2'
125
- - - "<"
126
- - !ruby/object:Gem::Version
127
- version: 5.2.2.rc1
119
+ version: '6.0'
128
120
  type: :runtime
129
121
  prerelease: false
130
122
  version_requirements: !ruby/object:Gem::Requirement
131
123
  requirements:
132
124
  - - ">="
133
125
  - !ruby/object:Gem::Version
134
- version: '4.2'
135
- - - "<"
136
- - !ruby/object:Gem::Version
137
- version: 5.2.2.rc1
126
+ version: '6.0'
138
127
  description: Simulate multi-table inheritance for activerecord models using a polymorphic
139
128
  association
140
129
  email:
141
130
  - hsn.zamani@gmail.com
142
131
  - manuel@krautcomputing.com
132
+ - bourguiba.chedli@gmail.com
143
133
  executables:
144
134
  - console
145
135
  extensions: []
@@ -158,10 +148,9 @@ files:
158
148
  - _config.yml
159
149
  - active_record-acts_as.gemspec
160
150
  - bin/console
161
- - gemfiles/rails_4.2.gemfile
162
- - gemfiles/rails_5.0.gemfile
163
- - gemfiles/rails_5.1.gemfile
164
- - gemfiles/rails_5.2.gemfile
151
+ - gemfiles/rails_6.0.gemfile
152
+ - gemfiles/rails_6.1.gemfile
153
+ - gemfiles/rails_master.gemfile
165
154
  - lib/active_record/acts_as.rb
166
155
  - lib/active_record/acts_as/class_methods.rb
167
156
  - lib/active_record/acts_as/instance_methods.rb
@@ -174,15 +163,16 @@ files:
174
163
  - spec/active_record_spec.rb
175
164
  - spec/acts_as_spec.rb
176
165
  - spec/database_helper.rb
166
+ - spec/find_or_initialize_by_spec.rb
177
167
  - spec/migrations_spec.rb
178
168
  - spec/models.rb
179
169
  - spec/rspec_matchers_spec.rb
180
170
  - spec/spec_helper.rb
181
- homepage: http://github.com/krautcomputing/active_record-acts_as
171
+ homepage: http://github.com/chaadow/active_record-acts_as
182
172
  licenses:
183
173
  - MIT
184
174
  metadata: {}
185
- post_install_message:
175
+ post_install_message:
186
176
  rdoc_options: []
187
177
  require_paths:
188
178
  - lib
@@ -190,16 +180,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
180
  requirements:
191
181
  - - ">="
192
182
  - !ruby/object:Gem::Version
193
- version: '2.2'
183
+ version: '2.5'
194
184
  required_rubygems_version: !ruby/object:Gem::Requirement
195
185
  requirements:
196
186
  - - ">="
197
187
  - !ruby/object:Gem::Version
198
188
  version: '0'
199
189
  requirements: []
200
- rubyforge_project:
201
- rubygems_version: 2.7.6
202
- signing_key:
190
+ rubygems_version: 3.2.3
191
+ signing_key:
203
192
  specification_version: 4
204
193
  summary: Simulate multi-table inheritance for activerecord models
205
194
  test_files:
@@ -207,6 +196,7 @@ test_files:
207
196
  - spec/active_record_spec.rb
208
197
  - spec/acts_as_spec.rb
209
198
  - spec/database_helper.rb
199
+ - spec/find_or_initialize_by_spec.rb
210
200
  - spec/migrations_spec.rb
211
201
  - spec/models.rb
212
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.rc1"
7
-
8
- gemspec path: "../"