active_record-acts_as 1.0.0.rc → 1.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
  SHA1:
3
- metadata.gz: c137b5172e254e835624861325efa82e6ca2e609
4
- data.tar.gz: c1836efae6258976e635b8232d1c7654b3e33838
3
+ metadata.gz: 3d5548c95a54d8cbe26c5714273ec3ca3a3bf0ff
4
+ data.tar.gz: 70a127389d745b09cf38eba99f120cc9fa42e692
5
5
  SHA512:
6
- metadata.gz: 17f92b735d3520d7a66da1f75b6e7455963df6d1721557faceaca82c98949fbaab4110588f8254b94268dbeb30ddba1d6f1226424f1cf5edfb3e9e8db61effe2
7
- data.tar.gz: 14117fe50dfde347a40a607ac783eca19aedbc46fe3c1a4d66a1bbdb594deb26c4e185d584fa68200c39ad020e7be4af6cc3908fe77356ebe346510015a51815
6
+ metadata.gz: 18d8183369e11b5b136f76e2b94d3d4ffad186113f1266031a92f6960abea9a45577ab5e718a5130b4b609939ea62f49f4993e0df777cf646d669ac074f0795c
7
+ data.tar.gz: cf442a282239a0a618dbf78b10ff234286537ba38fb2a5c78b098d9b3754ec268591405e9d4fbf6ee8eb2f5a20c9068fce9d922c28596227138012afb8835f71
data/README.md CHANGED
@@ -16,11 +16,11 @@ A product has common attributes (`name`, `price`, `image` ...),
16
16
  while each type of product has its own attributes:
17
17
  for example a `pen` has `color`, a `book` has `author` and `publisher` and so on.
18
18
  With multiple-table-inheritance you can have a `products` table with common columns and
19
- a seprate table for each product type, i.e. a `pens` table with `color` column.
19
+ a separate table for each product type, i.e. a `pens` table with `color` column.
20
20
 
21
21
  ## Requirements
22
22
 
23
- `AciveRecord ~> 4`
23
+ `AciveRecord ~> 4.1.2` or newest
24
24
 
25
25
  ## Installation
26
26
 
@@ -121,7 +121,7 @@ You can give a name to all methods in `:as` option:
121
121
 
122
122
  ```Ruby
123
123
  class Product < ActiveRecord::Base
124
- actable as: producible
124
+ actable as: :producible
125
125
  end
126
126
 
127
127
  class Pen < ActiveRecord::Base
@@ -133,10 +133,10 @@ change_table :products do |t|
133
133
  end
134
134
  ```
135
135
 
136
- `acts_as` support all `has_one` options, where defauls are there:
136
+ `acts_as` support all `has_one` options, where defaults are there:
137
137
  `as: :actable, dependent: :destroy, validate: false, autosave: true`
138
138
 
139
- Make sure you know what you are doing when ovrewriting `validate` or `autodave` options.
139
+ Make sure you know what you are doing when overwriting `validate` or `autodave` options.
140
140
 
141
141
  You can pass scope to `acts_as` as in `has_one`:
142
142
 
@@ -147,7 +147,7 @@ acts_as :person, -> { includes(:friends) }
147
147
  `actable` support all `belongs_to` options, where defaults are these:
148
148
  `polymorphic: true, dependent: :delete, autosave: true`
149
149
 
150
- Make sure you know what you are doing when ovrewriting `polymorphic` option.
150
+ Make sure you know what you are doing when overwriting `polymorphic` option.
151
151
 
152
152
 
153
153
  ## Migrating from acts_as_relation
@@ -160,7 +160,7 @@ Replace `acts_as_superclass` in models with `actable` and if you where using
160
160
 
161
161
  1. Fork it ( https://github.com/hzamani/active_record-acts_as/fork )
162
162
  2. Create your feature branch (`git checkout -b my-new-feature`)
163
- 3. Test changes don't breake anything (`rspec`)
163
+ 3. Test changes don't break anything (`rspec`)
164
164
  4. Add specs for your new feature
165
165
  5. Commit your changes (`git commit -am 'Add some feature'`)
166
166
  6. Push to the branch (`git push origin my-new-feature`)
@@ -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"
29
+ spec.add_dependency "activerecord", "~> 4.1.2"
30
30
  end
@@ -15,7 +15,7 @@ module ActiveRecord
15
15
 
16
16
  cattr_reader(:acting_as_reflection) { reflections[name.to_sym] }
17
17
  cattr_reader(:acting_as_name) { name.to_s }
18
- cattr_reader(:acting_as_model) { name.to_s.camelize.constantize }
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"
20
20
  alias_method :acting_as=, "#{name}=".to_sym
21
21
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  module ActiveRecord
3
3
  module ActsAs
4
- VERSION = "1.0.0.rc"
4
+ VERSION = "1.0.0"
5
5
  end
6
6
  end
data/spec/actable_spec.rb CHANGED
@@ -30,6 +30,11 @@ RSpec.describe "ActiveRecord::Base subclass with #actable" do
30
30
  end
31
31
  end
32
32
 
33
+ it "raises NoMethodError for undefined methods on specific" do
34
+ pen.save
35
+ expect{ pen.product.raise_error }.to raise_error(NoMethodError, /undefined method `non_existant_method' for #<Pen/)
36
+ end
37
+
33
38
  it "deletes specific subclass on destroy" do
34
39
  pen.save
35
40
  pen.product.destroy
data/spec/acts_as_spec.rb CHANGED
@@ -14,6 +14,10 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
14
14
  expect(association.options).to have_key(:as)
15
15
  end
16
16
 
17
+ it "has a cattr_reader for the acting_as_model" do
18
+ expect(subject.acting_as_model).to eq Product
19
+ end
20
+
17
21
  describe "#acting_as?" do
18
22
  it "returns true for supermodel class and name" do
19
23
  expect(Pen.acting_as? :product).to be true
@@ -180,4 +184,19 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
180
184
  expect(relation.scope_for_create[:name]).to eq('new name')
181
185
  end
182
186
  end
187
+
188
+ context 'Namespaces' do
189
+ subject { Inventory::PenLid }
190
+
191
+ it "has a has_one relation" do
192
+ association = subject.reflect_on_all_associations.find { |r| r.name == :product_feature }
193
+ expect(association).to_not be_nil
194
+ expect(association.macro).to eq(:has_one)
195
+ expect(association.options).to have_key(:as)
196
+ end
197
+
198
+ it "has a cattr_reader for the acting_as_model" do
199
+ expect(subject.acting_as_model).to eq Inventory::ProductFeature
200
+ end
201
+ end
183
202
  end
data/spec/models.rb CHANGED
@@ -9,6 +9,10 @@ class Product < ActiveRecord::Base
9
9
  def present
10
10
  "#{name} - $#{price}"
11
11
  end
12
+
13
+ def raise_error
14
+ specific.non_existant_method
15
+ end
12
16
  end
13
17
 
14
18
  class Pen < ActiveRecord::Base
@@ -21,6 +25,25 @@ class Store < ActiveRecord::Base
21
25
  has_many :products
22
26
  end
23
27
 
28
+ module Inventory
29
+ class ProductFeature < ActiveRecord::Base
30
+ self.table_name = 'inventory_product_features'
31
+ actable
32
+ validates_presence_of :name, :price
33
+
34
+ def present
35
+ "#{name} - $#{price}"
36
+ end
37
+ end
38
+
39
+ class PenLid < ActiveRecord::Base
40
+ self.table_name = 'inventory_pen_lids'
41
+ acts_as :product_feature, class_name: 'Inventory::ProductFeature'
42
+
43
+ validates_presence_of :color
44
+ end
45
+ end
46
+
24
47
  initialize_database do
25
48
  create_table :pens do |t|
26
49
  t.string :color
@@ -36,4 +59,14 @@ initialize_database do
36
59
  create_table :stores do |t|
37
60
  t.string :name
38
61
  end
62
+
63
+ create_table :inventory_pen_lids do |t|
64
+ t.string :color
65
+ end
66
+
67
+ create_table :inventory_product_features do |t|
68
+ t.string :name
69
+ t.float :price
70
+ t.actable
71
+ end
39
72
  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.0.rc
4
+ version: 1.0.0
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-07-29 00:00:00.000000000 Z
11
+ date: 2014-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '4'
89
+ version: 4.1.2
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '4'
96
+ version: 4.1.2
97
97
  description: Simulate multi-table inheritance for activerecord models using a plymorphic
98
98
  association
99
99
  email:
@@ -138,9 +138,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
138
  version: '1.9'
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  requirements:
141
- - - ">"
141
+ - - ">="
142
142
  - !ruby/object:Gem::Version
143
- version: 1.3.1
143
+ version: '0'
144
144
  requirements: []
145
145
  rubyforge_project:
146
146
  rubygems_version: 2.2.2