datts_right 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/datts_right.gemspec +25 -1
- data/lib/datts_right/instance_methods.rb +29 -0
- data/spec/datts_right/add_dynamic_attributes_spec.rb +37 -0
- data/spec/datts_right/attributes_spec.rb +21 -0
- data/spec/datts_right/remove_dynamic_attribute_spec.rb +26 -0
- data/spec/datts_right_spec.rb +18 -0
- data/spec/spec_helper.rb +1 -0
- metadata +99 -3
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.13
|
data/datts_right.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{datts_right}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.13"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ramon Tayag"]
|
@@ -35,6 +35,9 @@ Gem::Specification.new do |s|
|
|
35
35
|
"lib/datts_right/page.rb",
|
36
36
|
"lib/datts_right/query_methods.rb",
|
37
37
|
"spec/datt_spec.rb",
|
38
|
+
"spec/datts_right/add_dynamic_attributes_spec.rb",
|
39
|
+
"spec/datts_right/attributes_spec.rb",
|
40
|
+
"spec/datts_right/remove_dynamic_attribute_spec.rb",
|
38
41
|
"spec/datts_right_spec.rb",
|
39
42
|
"spec/spec_helper.rb"
|
40
43
|
]
|
@@ -45,6 +48,9 @@ Gem::Specification.new do |s|
|
|
45
48
|
s.summary = %q{Allows saving of dynamic attributes in your ActiveRecord model}
|
46
49
|
s.test_files = [
|
47
50
|
"spec/datt_spec.rb",
|
51
|
+
"spec/datts_right/add_dynamic_attributes_spec.rb",
|
52
|
+
"spec/datts_right/attributes_spec.rb",
|
53
|
+
"spec/datts_right/remove_dynamic_attribute_spec.rb",
|
48
54
|
"spec/datts_right_spec.rb",
|
49
55
|
"spec/spec_helper.rb"
|
50
56
|
]
|
@@ -200,6 +206,12 @@ Gem::Specification.new do |s|
|
|
200
206
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
201
207
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
202
208
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
209
|
+
s.add_development_dependency(%q<autotest>, [">= 0"])
|
210
|
+
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
211
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
212
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
213
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
214
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
203
215
|
else
|
204
216
|
s.add_dependency(%q<datts_right>, [">= 0"])
|
205
217
|
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
@@ -348,6 +360,12 @@ Gem::Specification.new do |s|
|
|
348
360
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
349
361
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
350
362
|
s.add_dependency(%q<rcov>, [">= 0"])
|
363
|
+
s.add_dependency(%q<autotest>, [">= 0"])
|
364
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
365
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
366
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
367
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
368
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
351
369
|
end
|
352
370
|
else
|
353
371
|
s.add_dependency(%q<datts_right>, [">= 0"])
|
@@ -497,6 +515,12 @@ Gem::Specification.new do |s|
|
|
497
515
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
498
516
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
499
517
|
s.add_dependency(%q<rcov>, [">= 0"])
|
518
|
+
s.add_dependency(%q<autotest>, [">= 0"])
|
519
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
520
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
521
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
522
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
523
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
500
524
|
end
|
501
525
|
end
|
502
526
|
|
@@ -73,6 +73,35 @@ module DattsRight
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
def attributes=(new_attributes, guard_protected_attributes = true)
|
77
|
+
return unless new_attributes.is_a?(Hash)
|
78
|
+
attributes = new_attributes.stringify_keys
|
79
|
+
|
80
|
+
multi_parameter_attributes = []
|
81
|
+
attributes = sanitize_for_mass_assignment(attributes) if guard_protected_attributes
|
82
|
+
|
83
|
+
attributes.each do |k, v|
|
84
|
+
if k.include?("(")
|
85
|
+
multi_parameter_attributes << [ k, v ]
|
86
|
+
else
|
87
|
+
#respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(UnknownAttributeError, "unknown attribute: #{k}")
|
88
|
+
begin
|
89
|
+
send("#{k}=", v)
|
90
|
+
#puts "Set super #{k} to #{v}"
|
91
|
+
rescue NoMethodError => e
|
92
|
+
#puts "NoMethodError was raised: #{e}, so we now check to see if '#{k}' is dynamic_attribute"
|
93
|
+
if dynamic_attribute?(k)
|
94
|
+
write_dynamic_attribute("#{k}", v)
|
95
|
+
else
|
96
|
+
raise ActiveRecord::UnknownAttributeError, "unknown attribute: #{k}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
assign_multiparameter_attributes(multi_parameter_attributes)
|
103
|
+
end
|
104
|
+
|
76
105
|
private
|
77
106
|
|
78
107
|
# Called after validation on update so that dynamic attributes behave
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe DattsRight, ".add_dynamic_attribute(attr_key, object_type)" do
|
4
|
+
before do
|
5
|
+
reset_database
|
6
|
+
@page = Page.create
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be aliased by add_datt" do
|
10
|
+
Page.instance_method(:add_dynamic_attribute).should == Page.instance_method(:add_datt)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should add a dynamic attribute" do
|
14
|
+
@page.add_dynamic_attribute(:rocks, "string")
|
15
|
+
@page.dynamic_attribute_details(:rocks).value.should be_nil
|
16
|
+
@page.add_dynamic_attribute(:rock, "string", "123")
|
17
|
+
@page.read_datt(:rock).should == "123"
|
18
|
+
@page.dynamic_attribute_details(:rock).value.should == "123"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should ignore when trying to add same attribute" do
|
22
|
+
@page.add_dynamic_attribute(:rocks, "string")
|
23
|
+
@page.add_dynamic_attribute(:rocks, "integer")
|
24
|
+
@page.dynamic_attribute_details(:rocks).object_type.should == "string"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return false if the method that is being added already exists" do
|
28
|
+
@page.add_dynamic_attribute(:name, "text").should be_false
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should not make any changes to the original attribute" do
|
32
|
+
@page.update_attribute(:name, "juno")
|
33
|
+
@page.add_dynamic_attribute(:name, "text")
|
34
|
+
@page.name.should == "juno"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe DattsRight, ".attributes=" do
|
4
|
+
before do
|
5
|
+
reset_database
|
6
|
+
@page = Page.create
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should accept a mix of normal and dynamic attributes" do
|
10
|
+
@page.add_dynamic_attribute(:price, "integer", 200)
|
11
|
+
@page.attributes = {:name => "fark", :price => 300}
|
12
|
+
@page.name.should == "fark"
|
13
|
+
@page.read_datt(:price).should == 300
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should raise UnknownAttributeError if the attribute doesn't exist" do
|
17
|
+
lambda {
|
18
|
+
@page.attributes = {:name => "fark", :body => "lark"}
|
19
|
+
}.should raise_error(ActiveRecord::UnknownAttributeError, "unknown attribute: body")
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe DattsRight, ".remove_dynamic_attribute(attr_key)" do
|
4
|
+
before do
|
5
|
+
reset_database
|
6
|
+
@page = Page.create
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be aliased by remove_datt" do
|
10
|
+
Page.instance_method(:remove_dynamic_attribute).should == Page.instance_method(:remove_datt)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should remove the attribute completely" do
|
14
|
+
@page.add_dynamic_attribute(:rocks, "string")
|
15
|
+
@page.remove_dynamic_attribute(:rocks)
|
16
|
+
lambda { @page.rocks }.should raise_error(NoMethodError)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not explode if the attribute being removed isn't there" do
|
20
|
+
@page.add_dynamic_attribute(:rocks, "string")
|
21
|
+
@page.remove_dynamic_attribute(:rocks)
|
22
|
+
lambda {
|
23
|
+
@page.remove_dynamic_attribute(:rocks)
|
24
|
+
}.should_not raise_error(NoMethodError)
|
25
|
+
end
|
26
|
+
end
|
data/spec/datts_right_spec.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
# Raised when unknown attributes are supplied via mass assignment.
|
3
|
+
#class UnknownAttributeError < NoMethodError
|
4
|
+
#end
|
2
5
|
|
3
6
|
describe DattsRight do
|
4
7
|
before do
|
@@ -435,4 +438,19 @@ describe DattsRight do
|
|
435
438
|
@page.save
|
436
439
|
@page.body.should == "dude"
|
437
440
|
end
|
441
|
+
|
442
|
+
describe ".attributes=" do
|
443
|
+
it "should accept a mix of normal and dynamic attributes" do
|
444
|
+
@page.add_dynamic_attribute(:price, "integer", 200)
|
445
|
+
@page.attributes = {:name => "fark", :price => 300}
|
446
|
+
@page.name.should == "fark"
|
447
|
+
@page.read_datt(:price).should == 300
|
448
|
+
end
|
449
|
+
|
450
|
+
it "should raise UnknownAttributeError if the attribute doesn't exist" do
|
451
|
+
lambda {
|
452
|
+
@page.attributes = {:name => "fark", :body => "lark"}
|
453
|
+
}.should raise_error(ActiveRecord::UnknownAttributeError, "unknown attribute: body")
|
454
|
+
end
|
455
|
+
end
|
438
456
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datts_right
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 13
|
10
|
+
version: 0.0.13
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ramon Tayag
|
@@ -2224,6 +2224,96 @@ dependencies:
|
|
2224
2224
|
name: rcov
|
2225
2225
|
version_requirements: *id147
|
2226
2226
|
prerelease: false
|
2227
|
+
- !ruby/object:Gem::Dependency
|
2228
|
+
type: :development
|
2229
|
+
requirement: &id148 !ruby/object:Gem::Requirement
|
2230
|
+
none: false
|
2231
|
+
requirements:
|
2232
|
+
- - ">="
|
2233
|
+
- !ruby/object:Gem::Version
|
2234
|
+
hash: 3
|
2235
|
+
segments:
|
2236
|
+
- 0
|
2237
|
+
version: "0"
|
2238
|
+
name: autotest
|
2239
|
+
version_requirements: *id148
|
2240
|
+
prerelease: false
|
2241
|
+
- !ruby/object:Gem::Dependency
|
2242
|
+
type: :development
|
2243
|
+
requirement: &id149 !ruby/object:Gem::Requirement
|
2244
|
+
none: false
|
2245
|
+
requirements:
|
2246
|
+
- - ">="
|
2247
|
+
- !ruby/object:Gem::Version
|
2248
|
+
hash: 3
|
2249
|
+
segments:
|
2250
|
+
- 0
|
2251
|
+
version: "0"
|
2252
|
+
name: sqlite3
|
2253
|
+
version_requirements: *id149
|
2254
|
+
prerelease: false
|
2255
|
+
- !ruby/object:Gem::Dependency
|
2256
|
+
type: :development
|
2257
|
+
requirement: &id150 !ruby/object:Gem::Requirement
|
2258
|
+
none: false
|
2259
|
+
requirements:
|
2260
|
+
- - ~>
|
2261
|
+
- !ruby/object:Gem::Version
|
2262
|
+
hash: 3
|
2263
|
+
segments:
|
2264
|
+
- 2
|
2265
|
+
- 3
|
2266
|
+
- 0
|
2267
|
+
version: 2.3.0
|
2268
|
+
name: rspec
|
2269
|
+
version_requirements: *id150
|
2270
|
+
prerelease: false
|
2271
|
+
- !ruby/object:Gem::Dependency
|
2272
|
+
type: :development
|
2273
|
+
requirement: &id151 !ruby/object:Gem::Requirement
|
2274
|
+
none: false
|
2275
|
+
requirements:
|
2276
|
+
- - ~>
|
2277
|
+
- !ruby/object:Gem::Version
|
2278
|
+
hash: 23
|
2279
|
+
segments:
|
2280
|
+
- 1
|
2281
|
+
- 0
|
2282
|
+
- 0
|
2283
|
+
version: 1.0.0
|
2284
|
+
name: bundler
|
2285
|
+
version_requirements: *id151
|
2286
|
+
prerelease: false
|
2287
|
+
- !ruby/object:Gem::Dependency
|
2288
|
+
type: :development
|
2289
|
+
requirement: &id152 !ruby/object:Gem::Requirement
|
2290
|
+
none: false
|
2291
|
+
requirements:
|
2292
|
+
- - ~>
|
2293
|
+
- !ruby/object:Gem::Version
|
2294
|
+
hash: 7
|
2295
|
+
segments:
|
2296
|
+
- 1
|
2297
|
+
- 5
|
2298
|
+
- 2
|
2299
|
+
version: 1.5.2
|
2300
|
+
name: jeweler
|
2301
|
+
version_requirements: *id152
|
2302
|
+
prerelease: false
|
2303
|
+
- !ruby/object:Gem::Dependency
|
2304
|
+
type: :development
|
2305
|
+
requirement: &id153 !ruby/object:Gem::Requirement
|
2306
|
+
none: false
|
2307
|
+
requirements:
|
2308
|
+
- - ">="
|
2309
|
+
- !ruby/object:Gem::Version
|
2310
|
+
hash: 3
|
2311
|
+
segments:
|
2312
|
+
- 0
|
2313
|
+
version: "0"
|
2314
|
+
name: rcov
|
2315
|
+
version_requirements: *id153
|
2316
|
+
prerelease: false
|
2227
2317
|
description: Creates a separate table that saves all your dynamic attributes.
|
2228
2318
|
email: ramon@tayag.net
|
2229
2319
|
executables: []
|
@@ -2252,6 +2342,9 @@ files:
|
|
2252
2342
|
- lib/datts_right/page.rb
|
2253
2343
|
- lib/datts_right/query_methods.rb
|
2254
2344
|
- spec/datt_spec.rb
|
2345
|
+
- spec/datts_right/add_dynamic_attributes_spec.rb
|
2346
|
+
- spec/datts_right/attributes_spec.rb
|
2347
|
+
- spec/datts_right/remove_dynamic_attribute_spec.rb
|
2255
2348
|
- spec/datts_right_spec.rb
|
2256
2349
|
- spec/spec_helper.rb
|
2257
2350
|
has_rdoc: true
|
@@ -2290,5 +2383,8 @@ specification_version: 3
|
|
2290
2383
|
summary: Allows saving of dynamic attributes in your ActiveRecord model
|
2291
2384
|
test_files:
|
2292
2385
|
- spec/datt_spec.rb
|
2386
|
+
- spec/datts_right/add_dynamic_attributes_spec.rb
|
2387
|
+
- spec/datts_right/attributes_spec.rb
|
2388
|
+
- spec/datts_right/remove_dynamic_attribute_spec.rb
|
2293
2389
|
- spec/datts_right_spec.rb
|
2294
2390
|
- spec/spec_helper.rb
|