active_record-acts_as 1.0.6 → 1.0.7

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
  SHA1:
3
- metadata.gz: 64cbfe3c6d86757fceca3cd920138468bac93d4b
4
- data.tar.gz: 4687d0558602f189e3c771174aa986afadf3b4cb
3
+ metadata.gz: 7387f8a9b958e1010c9c86367631e5be078d6329
4
+ data.tar.gz: 31705e7f709ae00673bc2cf9bddcf72cc7a2eda9
5
5
  SHA512:
6
- metadata.gz: 26021ad15fd01db7dcbad29e912ed2a6b96a66ed148f8e442bca9f8c5ace9786c4171b6d318773639a1de20b04ce0a28420f72ef1dd0d2c5a218189ead20c883
7
- data.tar.gz: 3912076316e37325948021045815231891e045fa5ac5488830399d68b61d5d1e5296fc20a771efbc4ee7184a56b2ad79db76b7e459fd6a817f20f74e01a80e17
6
+ metadata.gz: 507a0fd8e3609ceb749a1f8a3ee9ae051de0094fb769778a661ff91f0ed9bf0bb4f8001267c68db76f70f02f64f0c088d48533c599f40d76b12eacf1e8932b04
7
+ data.tar.gz: aebd0d7c848b0f53639491582c3d29187ed0d152324d861ebfbbb0441f792c83a61f95bb8d0d8ccce6993be6f899203dc0d1c790ac523c09d16d3f55179a4e85
data/README.md CHANGED
@@ -44,6 +44,7 @@ Back to example above, all you have to do is to mark `Product` as `actable` and
44
44
  ```Ruby
45
45
  class Product < ActiveRecord::Base
46
46
  actable
47
+ belongs_to :store
47
48
 
48
49
  validates_presence_of :name, :price
49
50
 
@@ -3,6 +3,7 @@ require 'active_record'
3
3
  require 'active_record/acts_as/version'
4
4
  require 'active_record/acts_as/relation'
5
5
  require 'active_record/acts_as/migration'
6
+ require 'active_record/acts_as/class_methods'
6
7
  require 'active_record/acts_as/instance_methods'
7
8
  require 'active_record/acts_as/querying'
8
9
 
@@ -0,0 +1,14 @@
1
+ module ActiveRecord
2
+ module ActsAs
3
+ module ClassMethods
4
+ def self.included(module_)
5
+ module_.alias_method_chain :_reflections, :acts_as
6
+ end
7
+
8
+ def _reflections_with_acts_as
9
+ @_reflections_acts_as_cache ||=
10
+ _reflections_without_acts_as.reverse_merge(acting_as_model._reflections)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -72,6 +72,22 @@ module ActiveRecord
72
72
  acting_as_persisted? ? super | (acting_as.attribute_names - [acting_as_reflection.type, acting_as_reflection.foreign_key]) : super
73
73
  end
74
74
 
75
+ def has_attribute?(attr_name, as_original_class = false)
76
+ if as_original_class
77
+ super(attr_name)
78
+ else
79
+ super(attr_name) || acting_as.has_attribute?(attr_name)
80
+ end
81
+ end
82
+
83
+ def column_for_attribute(name)
84
+ if has_attribute?(name, true)
85
+ super(name)
86
+ else
87
+ acting_as.column_for_attribute(name)
88
+ end
89
+ end
90
+
75
91
 
76
92
  def respond_to?(name, include_private = false, as_original_class = false)
77
93
  as_original_class ? super(name, include_private) : super(name, include_private) || acting_as.respond_to?(name)
@@ -22,6 +22,9 @@ module ActiveRecord
22
22
  alias_method :acting_as=, "#{name}=".to_sym
23
23
 
24
24
  include ActsAs::InstanceMethods
25
+ singleton_class.module_eval do
26
+ include ActsAs::ClassMethods
27
+ end
25
28
  end
26
29
 
27
30
  def acting_as?(other = nil)
@@ -1,6 +1,6 @@
1
1
 
2
2
  module ActiveRecord
3
3
  module ActsAs
4
- VERSION = "1.0.6"
4
+ VERSION = "1.0.7"
5
5
  end
6
6
  end
@@ -111,6 +111,40 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
111
111
  end
112
112
  end
113
113
 
114
+ describe "#has_attribute?" do
115
+ context "when the attribute is defined on the superclass" do
116
+ it "queries the superclass" do
117
+ expect(pen.has_attribute?(:name)).to be_truthy
118
+ end
119
+ end
120
+
121
+ context "when the attribute is defined on the subclass" do
122
+ it "queries the subclass" do
123
+ expect(pen.has_attribute?(:color)).to be_truthy
124
+ end
125
+ end
126
+ end
127
+
128
+ describe "#column_for_attribute" do
129
+ context "when the attribute is defined on the superclass" do
130
+ it "queries the superclass" do
131
+ expect(pen.column_for_attribute(:name)).to eq(pen.product.column_for_attribute(:name))
132
+ end
133
+ end
134
+
135
+ context "when the attribute is defined on the subclass" do
136
+ it "queries the subclass" do
137
+ expect(pen.column_for_attribute(:color)).not_to be_nil
138
+ end
139
+ end
140
+ end
141
+
142
+ describe "._reflections" do
143
+ it "merges the reflections on both superclass and subclass" do
144
+ expect(Pen._reflections.length).to eq(Product._reflections.length + 1)
145
+ end
146
+ end
147
+
114
148
  it "have supermodel attributes accessible on creation" do
115
149
  expect{Pen.create(pen_attributes)}.to_not raise_error
116
150
  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.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hassan Zamani
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-16 00:00:00.000000000 Z
11
+ date: 2015-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3
@@ -117,6 +117,7 @@ files:
117
117
  - Rakefile
118
118
  - active_record-acts_as.gemspec
119
119
  - lib/active_record/acts_as.rb
120
+ - lib/active_record/acts_as/class_methods.rb
120
121
  - lib/active_record/acts_as/instance_methods.rb
121
122
  - lib/active_record/acts_as/migration.rb
122
123
  - lib/active_record/acts_as/querying.rb
@@ -149,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
150
  version: '0'
150
151
  requirements: []
151
152
  rubyforge_project:
152
- rubygems_version: 2.4.5
153
+ rubygems_version: 2.4.8
153
154
  signing_key:
154
155
  specification_version: 4
155
156
  summary: Simulate multi-table inheritance for activerecord models