active_record-acts_as 3.0.2 → 3.1.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: f8c154ba79657fb9d0f37bf212375dd1c948f3603d822e66b577c4d83abf383c
4
- data.tar.gz: 3ea39c3f20af0cc3d842d619d5cc381c422ad1eb64a47f100d5133fcdfb88f7d
3
+ metadata.gz: bbfc7ea492327e566ab788c73aeb7d294a9d9b4f66049464c9bdcdd5e293bd2a
4
+ data.tar.gz: f9142f0468e292d87c4d0637970ca49823cc44664eb59fe09e975d3fe887fc04
5
5
  SHA512:
6
- metadata.gz: 3c94bddeccbdc361c0d05616f98113a8054ffab19bcaf89f7c269462162eec7eff38d30f44304a875a8245d6040584bda99c9e37026b672e6523fb4b4579c4e5
7
- data.tar.gz: a16eae6ff16a7611f9192add9e2e9b4bc500b4f9e8d17e6ead89d443e3ab10baa8f93d15490d7e2c193406c0e3576e9afbc19cd801d822c21d2e7c7904a6a463
6
+ metadata.gz: a1ac325e5b476330009606cad7248eb51c62ef8e5bf55ea1ac3ed099e55392716a7aceed1b0f6078a3031f4ab29ddcd86fd634c490289c41ff293381609fc68f
7
+ data.tar.gz: 3aaaf59d5b1b229bcedefb4135ba16df442016680096071c1ce6de076293158e803cc670ecda0f67ab991a4ee4a9112db44e63f757004cc759f17102deead977
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Hassan Zamani", "Manuel Meurer"]
10
10
  spec.email = ["hsn.zamani@gmail.com", "manuel@krautcomputing.com"]
11
11
  spec.summary = %q{Simulate multi-table inheritance for activerecord models}
12
- spec.description = %q{Simulate multi-table inheritance for activerecord models using a plymorphic association}
12
+ spec.description = %q{Simulate multi-table inheritance for activerecord models using a polymorphic association}
13
13
  spec.homepage = "http://github.com/krautcomputing/active_record-acts_as"
14
14
  spec.license = "MIT"
15
15
 
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
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", ">= 4.2", "< 5.2.2.rc1"
31
+ spec.add_dependency "activerecord", ">= 4.2", "< 5.2.2.rc1"
32
32
  end
@@ -76,10 +76,14 @@ module ActiveRecord
76
76
  super || acting_as?(klass)
77
77
  end
78
78
 
79
- def actable(options = {})
79
+ def actable(scope = nil, **options)
80
80
  name = options.delete(:as) || :actable
81
81
 
82
- reflections = belongs_to(name, options.reverse_merge(validate: false, polymorphic: true, dependent: :destroy, autosave: true, 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))
83
87
 
84
88
  cattr_reader(:actable_reflection) { reflections.stringify_keys[name.to_s] }
85
89
 
@@ -1,6 +1,6 @@
1
1
  module ActiveRecord
2
2
  module ActsAs
3
- VERSION = "3.0.2"
3
+ VERSION = "3.1.0"
4
4
  end
5
5
  end
6
6
 
@@ -411,6 +411,28 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
411
411
  end
412
412
  end
413
413
 
414
+ describe '.actable' do
415
+ class User < ActiveRecord::Base
416
+ actable -> { unscope(:where) }
417
+ end
418
+
419
+ class Customer < ActiveRecord::Base
420
+ default_scope { where('identifier > 1') }
421
+ acts_as :user
422
+
423
+ validates_presence_of :identifier
424
+ end
425
+
426
+ context 'with scope' do
427
+ it 'unscopes default scope' do
428
+ customer = Customer.create!(identifier: 1)
429
+ user = customer.user.reload
430
+ expect(user).to be_a User
431
+ expect(user.actable).to eq(customer)
432
+ end
433
+ end
434
+ end
435
+
414
436
  context 'class methods' do
415
437
  before(:each) { clear_database }
416
438
 
@@ -91,6 +91,15 @@ end
91
91
 
92
92
  def initialize_schema
93
93
  initialize_database do
94
+ create_table :users do |t|
95
+ t.timestamps null: true
96
+ t.actable
97
+ end
98
+
99
+ create_table :customers do |t|
100
+ t.integer :identifier
101
+ end
102
+
94
103
  create_table :pen_collections do |t|
95
104
  t.timestamps null: true
96
105
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-acts_as
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hassan Zamani
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-08-12 00:00:00.000000000 Z
12
+ date: 2018-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sqlite3
@@ -102,6 +102,9 @@ dependencies:
102
102
  - - ">="
103
103
  - !ruby/object:Gem::Version
104
104
  version: '4.2'
105
+ - - "<"
106
+ - !ruby/object:Gem::Version
107
+ version: 5.2.2.rc1
105
108
  type: :runtime
106
109
  prerelease: false
107
110
  version_requirements: !ruby/object:Gem::Requirement
@@ -109,6 +112,9 @@ dependencies:
109
112
  - - ">="
110
113
  - !ruby/object:Gem::Version
111
114
  version: '4.2'
115
+ - - "<"
116
+ - !ruby/object:Gem::Version
117
+ version: 5.2.2.rc1
112
118
  - !ruby/object:Gem::Dependency
113
119
  name: activerecord
114
120
  requirement: !ruby/object:Gem::Requirement
@@ -116,6 +122,9 @@ dependencies:
116
122
  - - ">="
117
123
  - !ruby/object:Gem::Version
118
124
  version: '4.2'
125
+ - - "<"
126
+ - !ruby/object:Gem::Version
127
+ version: 5.2.2.rc1
119
128
  type: :runtime
120
129
  prerelease: false
121
130
  version_requirements: !ruby/object:Gem::Requirement
@@ -123,7 +132,10 @@ dependencies:
123
132
  - - ">="
124
133
  - !ruby/object:Gem::Version
125
134
  version: '4.2'
126
- description: Simulate multi-table inheritance for activerecord models using a plymorphic
135
+ - - "<"
136
+ - !ruby/object:Gem::Version
137
+ version: 5.2.2.rc1
138
+ description: Simulate multi-table inheritance for activerecord models using a polymorphic
127
139
  association
128
140
  email:
129
141
  - hsn.zamani@gmail.com