active_record-acts_as 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/active_record-acts_as.gemspec +1 -1
- data/lib/active_record/acts_as/instance_methods.rb +3 -1
- data/lib/active_record/acts_as/relation.rb +2 -2
- data/lib/active_record/acts_as/version.rb +1 -1
- data/spec/actable_spec.rb +7 -0
- data/spec/acts_as_spec.rb +8 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34fc19a0853dc464c318bb8da5d55542940a7428
|
4
|
+
data.tar.gz: 9343cbe6c7b873b2a55af6e937042dc2fca10554
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdedabb5d9cff8c513c70f799b2a35527e896d37c452ea4c99ef01cff726988542179c85465588d70c701275c51b598b54f0cb164f5de63f814a67f470a98205
|
7
|
+
data.tar.gz: 8df4505d0d20012f9675dba4acd8512ebfc2d8c6cb64a9088853ccff6125af156132ec7cedae895810f5ac019d6f0c15543169da77e3b4c2fbed8779a60580ae
|
data/README.md
CHANGED
@@ -47,7 +47,7 @@ class Product < ActiveRecord::Base
|
|
47
47
|
|
48
48
|
validates_presence_of :name, :price
|
49
49
|
|
50
|
-
def
|
50
|
+
def info
|
51
51
|
"#{name} $#{price}"
|
52
52
|
end
|
53
53
|
end
|
@@ -66,7 +66,7 @@ end
|
|
66
66
|
```
|
67
67
|
|
68
68
|
and add foreign key and type columns to products table as in a polymorphic relation.
|
69
|
-
You may
|
69
|
+
You may prefer using a migration:
|
70
70
|
|
71
71
|
```Ruby
|
72
72
|
change_table :products do |t|
|
@@ -102,7 +102,7 @@ pen.valid?
|
|
102
102
|
# => false
|
103
103
|
pen.errors.full_messages
|
104
104
|
# => ["Name can't be blank", "Price can't be blank", "Color can't be blank"]
|
105
|
-
Pen.first.
|
105
|
+
Pen.first.info
|
106
106
|
# => "Penie! $0.8"
|
107
107
|
```
|
108
108
|
|
@@ -141,7 +141,7 @@ end
|
|
141
141
|
`acts_as` support all `has_one` options, where defaults are there:
|
142
142
|
`as: :actable, dependent: :destroy, validate: false, autosave: true`
|
143
143
|
|
144
|
-
Make sure you know what you are doing when overwriting `validate` or `
|
144
|
+
Make sure you know what you are doing when overwriting `validate` or `autosave` options.
|
145
145
|
|
146
146
|
You can pass scope to `acts_as` as in `has_one`:
|
147
147
|
|
@@ -13,7 +13,7 @@ module ActiveRecord
|
|
13
13
|
default_scope -> { eager_load(name) }
|
14
14
|
validate :actable_must_be_valid
|
15
15
|
|
16
|
-
cattr_reader(:acting_as_reflection) { reflections[name.
|
16
|
+
cattr_reader(:acting_as_reflection) { reflections.stringify_keys[name.to_s] }
|
17
17
|
cattr_reader(:acting_as_name) { name.to_s }
|
18
18
|
cattr_reader(:acting_as_model) { (options[:class_name] || name.to_s.camelize).constantize }
|
19
19
|
class_eval "def acting_as() #{name} || build_#{name} end"
|
@@ -47,7 +47,7 @@ module ActiveRecord
|
|
47
47
|
|
48
48
|
reflections = belongs_to name, {polymorphic: true, dependent: :delete, autosave: true}.merge(options)
|
49
49
|
|
50
|
-
cattr_reader(:actable_reflection) { reflections[name] }
|
50
|
+
cattr_reader(:actable_reflection) { reflections.stringify_keys[name.to_s] }
|
51
51
|
|
52
52
|
alias_method :specific, name
|
53
53
|
end
|
data/spec/actable_spec.rb
CHANGED
@@ -23,6 +23,13 @@ RSpec.describe "ActiveRecord::Base subclass with #actable" do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
describe "#actable_reflection" do
|
27
|
+
it "returns an activerecord assosiation reflection" do
|
28
|
+
expect(Product.actable_reflection).to_not be_nil
|
29
|
+
expect(Product.actable_reflection).to be_a(ActiveRecord::Reflection::AssociationReflection)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
26
33
|
describe ".specific" do
|
27
34
|
it "return specific submodel" do
|
28
35
|
pen.save
|
data/spec/acts_as_spec.rb
CHANGED
@@ -30,6 +30,13 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
describe "#acting_as_reflection" do
|
34
|
+
it "returns an activerecord assosiation reflection" do
|
35
|
+
expect(Pen.acting_as_reflection).to_not be_nil
|
36
|
+
expect(Pen.acting_as_reflection).to be_a(ActiveRecord::Reflection::AssociationReflection)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
33
40
|
describe ".acting_as?" do
|
34
41
|
it "returns true for supermodel class and name" do
|
35
42
|
expect(pen.acting_as? :product).to be true
|
@@ -85,6 +92,7 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
85
92
|
describe "#dup" do
|
86
93
|
it "duplicates actable model as well" do
|
87
94
|
p = pen.dup
|
95
|
+
expect(p).to be_a Pen
|
88
96
|
expect(p.name).to eq('pen')
|
89
97
|
expect(p.price).to eq(0.8)
|
90
98
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record-acts_as
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hassan Zamani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|
@@ -85,6 +85,9 @@ dependencies:
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4'
|
90
|
+
- - ">="
|
88
91
|
- !ruby/object:Gem::Version
|
89
92
|
version: 4.1.2
|
90
93
|
type: :runtime
|
@@ -92,6 +95,9 @@ dependencies:
|
|
92
95
|
version_requirements: !ruby/object:Gem::Requirement
|
93
96
|
requirements:
|
94
97
|
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '4'
|
100
|
+
- - ">="
|
95
101
|
- !ruby/object:Gem::Version
|
96
102
|
version: 4.1.2
|
97
103
|
description: Simulate multi-table inheritance for activerecord models using a plymorphic
|
@@ -143,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
149
|
version: '0'
|
144
150
|
requirements: []
|
145
151
|
rubyforge_project:
|
146
|
-
rubygems_version: 2.4.
|
152
|
+
rubygems_version: 2.4.5
|
147
153
|
signing_key:
|
148
154
|
specification_version: 4
|
149
155
|
summary: Simulate multi-table inheritance for activerecord models
|