datts_right 0.0.27 → 0.0.28
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.
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/datts_right.gemspec +5 -1
- data/lib/datts_right/instance_methods.rb +26 -0
- data/spec/datts_right/update_definition_spec.rb +37 -0
- data/spec/datts_right/update_definitions_spec.rb +14 -0
- metadata +7 -3
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.28
|
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.28"
|
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"]
|
@@ -55,6 +55,8 @@ Gem::Specification.new do |s|
|
|
55
55
|
"spec/datts_right/remove_definition_spec.rb",
|
56
56
|
"spec/datts_right/remove_definitions_spec.rb",
|
57
57
|
"spec/datts_right/remove_dynamic_attribute_spec.rb",
|
58
|
+
"spec/datts_right/update_definition_spec.rb",
|
59
|
+
"spec/datts_right/update_definitions_spec.rb",
|
58
60
|
"spec/datts_right/where_dynamic_attribute_spec.rb",
|
59
61
|
"spec/datts_right/with_dynamic_attribute_key_spec.rb",
|
60
62
|
"spec/datts_right/with_dynamic_attribute_type_spec.rb",
|
@@ -85,6 +87,8 @@ Gem::Specification.new do |s|
|
|
85
87
|
"spec/datts_right/remove_definition_spec.rb",
|
86
88
|
"spec/datts_right/remove_definitions_spec.rb",
|
87
89
|
"spec/datts_right/remove_dynamic_attribute_spec.rb",
|
90
|
+
"spec/datts_right/update_definition_spec.rb",
|
91
|
+
"spec/datts_right/update_definitions_spec.rb",
|
88
92
|
"spec/datts_right/where_dynamic_attribute_spec.rb",
|
89
93
|
"spec/datts_right/with_dynamic_attribute_key_spec.rb",
|
90
94
|
"spec/datts_right/with_dynamic_attribute_type_spec.rb",
|
@@ -179,6 +179,32 @@ module DattsRight
|
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
+
def update_definition(key, new_values={})
|
183
|
+
if dynamic_attributes_options[:definition]
|
184
|
+
if definition && definition[key]
|
185
|
+
attr_key = new_values.delete(:attr_key)
|
186
|
+
new_values.each do |k, v|
|
187
|
+
definition[key][k] = v
|
188
|
+
end
|
189
|
+
|
190
|
+
if attr_key
|
191
|
+
add_definition(attr_key, definition[key])
|
192
|
+
remove_definition(key)
|
193
|
+
end
|
194
|
+
else
|
195
|
+
raise NotDefinedError, "#{key} is not defined"
|
196
|
+
end
|
197
|
+
else
|
198
|
+
raise NoDefinitionError
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def update_definitions(hash={})
|
203
|
+
hash.each do |k, v|
|
204
|
+
update_definition k, v
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
182
208
|
def remove_definition(key)
|
183
209
|
if key
|
184
210
|
key = key.to_sym
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe DattsRight, ".update_definition(key, value)" do
|
4
|
+
before do
|
5
|
+
reset_database
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should update attr_key of a definition" do
|
9
|
+
c = Category.create
|
10
|
+
c.definition = {:robot => {:object_type => "string"}}
|
11
|
+
c.update_definition(:robot, :attr_key => "bodi")
|
12
|
+
c.definition[:robot].should be_nil
|
13
|
+
c.definition[:bodi].should == {:object_type => "string"}
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be able to update the rest (all except attr_key) of the definition" do
|
17
|
+
c = Category.create
|
18
|
+
c.definition = {:robot => {:object_type => "string", :desc => "hi"}}
|
19
|
+
c.update_definition(:robot, :object_type => "integer", :desc => "wyt")
|
20
|
+
c.definition[:robot].should == {:object_type => "integer", :desc => "wyt"}
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should raise NotDefinedError if it doesn't exist" do
|
24
|
+
lambda {Category.create.update_definition(:robot, {})}.should raise_error(DattsRight::NotDefinedError, "robot is not defined")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should raise NoDefinitionError if it doesn't have definition => true" do
|
28
|
+
lambda {Page.create.update_definition(:fake, {})}.should raise_error(DattsRight::NoDefinitionError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should be able to handle if definition is nil" do
|
32
|
+
c = Category.create
|
33
|
+
c.definition = nil
|
34
|
+
c.save
|
35
|
+
lambda {c.update_definition(:real, :object_type => "string")}.should raise_error(DattsRight::NotDefinedError)
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe DattsRight, ".update_definitions(hash={})" do
|
4
|
+
before do
|
5
|
+
reset_database
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should call update_definition the correct number of times" do
|
9
|
+
c = Category.create
|
10
|
+
c.should_receive(:update_definition).with(:mr, :object_type => "integer")
|
11
|
+
c.should_receive(:update_definition).with(:roboto, :object_type => "string")
|
12
|
+
c.update_definitions(:mr => {:object_type => "integer"}, :roboto => {:object_type => "string"})
|
13
|
+
end
|
14
|
+
end
|
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: 39
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 28
|
10
|
+
version: 0.0.28
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ramon Tayag
|
@@ -186,6 +186,8 @@ files:
|
|
186
186
|
- spec/datts_right/remove_definition_spec.rb
|
187
187
|
- spec/datts_right/remove_definitions_spec.rb
|
188
188
|
- spec/datts_right/remove_dynamic_attribute_spec.rb
|
189
|
+
- spec/datts_right/update_definition_spec.rb
|
190
|
+
- spec/datts_right/update_definitions_spec.rb
|
189
191
|
- spec/datts_right/where_dynamic_attribute_spec.rb
|
190
192
|
- spec/datts_right/with_dynamic_attribute_key_spec.rb
|
191
193
|
- spec/datts_right/with_dynamic_attribute_type_spec.rb
|
@@ -244,6 +246,8 @@ test_files:
|
|
244
246
|
- spec/datts_right/remove_definition_spec.rb
|
245
247
|
- spec/datts_right/remove_definitions_spec.rb
|
246
248
|
- spec/datts_right/remove_dynamic_attribute_spec.rb
|
249
|
+
- spec/datts_right/update_definition_spec.rb
|
250
|
+
- spec/datts_right/update_definitions_spec.rb
|
247
251
|
- spec/datts_right/where_dynamic_attribute_spec.rb
|
248
252
|
- spec/datts_right/with_dynamic_attribute_key_spec.rb
|
249
253
|
- spec/datts_right/with_dynamic_attribute_type_spec.rb
|