active_record-acts_as 1.0.2 → 1.0.3

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
  SHA1:
3
- metadata.gz: ecc2d344c7bbdff842f92553d2a7a028f5a7c34e
4
- data.tar.gz: 87136997ae1fccbffb70958662dc476fbb8a636c
3
+ metadata.gz: 34fc19a0853dc464c318bb8da5d55542940a7428
4
+ data.tar.gz: 9343cbe6c7b873b2a55af6e937042dc2fca10554
5
5
  SHA512:
6
- metadata.gz: 42685ddd2f09b51053c1547e76ba3a8470d308d34b2103d52c363b4a75bebcb529f878b7c1a25df5c3420f2454d6943a64af5845e5df510e7d9cb4badc986a8e
7
- data.tar.gz: 18f01b95fb9602ca9e6f4c7fe1393094847ff8ae5f3441d4804b9c4eaf5409bd249d342821b68e794af2d4673e17a5f601c3282a0f4c7fa7b882bf191f1ac2f2
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 display
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 prefere using a migration:
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.display
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 `autodave` options.
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
 
@@ -26,5 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rake", "~> 10"
27
27
 
28
28
  spec.add_dependency "activesupport", "~> 4"
29
- spec.add_dependency "activerecord", "~> 4.1.2"
29
+ spec.add_dependency "activerecord", "~> 4", ">= 4.1.2"
30
30
  end
@@ -50,7 +50,9 @@ module ActiveRecord
50
50
  end
51
51
 
52
52
  def dup
53
- super.acting_as = acting_as.dup
53
+ duplicate = super
54
+ duplicate.acting_as = acting_as.dup
55
+ duplicate
54
56
  end
55
57
 
56
58
  def method_missing(method, *args, &block)
@@ -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.to_sym] }
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
@@ -1,6 +1,6 @@
1
1
 
2
2
  module ActiveRecord
3
3
  module ActsAs
4
- VERSION = "1.0.2"
4
+ VERSION = "1.0.3"
5
5
  end
6
6
  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.2
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: 2014-08-17 00:00:00.000000000 Z
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.1
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