datts_right 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- datts_right (0.0.18)
4
+ datts_right (0.0.19)
5
5
  datts_right
6
6
  rails (>= 3.0.0)
7
7
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.19
1
+ 0.0.20
data/datts_right.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{datts_right}
8
- s.version = "0.0.19"
8
+ s.version = "0.0.20"
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"]
12
- s.date = %q{2011-04-19}
12
+ s.date = %q{2011-04-26}
13
13
  s.description = %q{Creates a separate table that saves all your dynamic attributes.}
14
14
  s.email = %q{ramon@tayag.net}
15
15
  s.extra_rdoc_files = [
@@ -33,17 +33,25 @@ Gem::Specification.new do |s|
33
33
  "lib/datts_right/category.rb",
34
34
  "lib/datts_right/dynamic_attribute.rb",
35
35
  "lib/datts_right/dynamic_attribute_definition.rb",
36
+ "lib/datts_right/errors.rb",
36
37
  "lib/datts_right/exceptions.rb",
37
38
  "lib/datts_right/instance_methods.rb",
38
39
  "lib/datts_right/page.rb",
39
40
  "lib/datts_right/query_methods.rb",
40
41
  "spec/datt_spec.rb",
42
+ "spec/datts_right/add_definition_spec.rb",
43
+ "spec/datts_right/add_dynamic_attribute_spec.rb",
41
44
  "spec/datts_right/add_dynamic_attributes_spec.rb",
42
45
  "spec/datts_right/attributes_spec.rb",
43
46
  "spec/datts_right/create_definitions_spec.rb",
47
+ "spec/datts_right/definition_spec.rb",
44
48
  "spec/datts_right/dynamic_attribute_definition_spec.rb",
49
+ "spec/datts_right/find_by_dynamic_attribute_spec.rb",
45
50
  "spec/datts_right/inheritance_spec.rb",
51
+ "spec/datts_right/read_dynamic_attribute_spec.rb",
52
+ "spec/datts_right/remove_definition_spec.rb",
46
53
  "spec/datts_right/remove_dynamic_attribute_spec.rb",
54
+ "spec/datts_right/where_dynamic_attribute_spec.rb",
47
55
  "spec/datts_right_spec.rb",
48
56
  "spec/spec_helper.rb"
49
57
  ]
@@ -54,12 +62,19 @@ Gem::Specification.new do |s|
54
62
  s.summary = %q{Allows saving of dynamic attributes in your ActiveRecord model}
55
63
  s.test_files = [
56
64
  "spec/datt_spec.rb",
65
+ "spec/datts_right/add_definition_spec.rb",
66
+ "spec/datts_right/add_dynamic_attribute_spec.rb",
57
67
  "spec/datts_right/add_dynamic_attributes_spec.rb",
58
68
  "spec/datts_right/attributes_spec.rb",
59
69
  "spec/datts_right/create_definitions_spec.rb",
70
+ "spec/datts_right/definition_spec.rb",
60
71
  "spec/datts_right/dynamic_attribute_definition_spec.rb",
72
+ "spec/datts_right/find_by_dynamic_attribute_spec.rb",
61
73
  "spec/datts_right/inheritance_spec.rb",
74
+ "spec/datts_right/read_dynamic_attribute_spec.rb",
75
+ "spec/datts_right/remove_definition_spec.rb",
62
76
  "spec/datts_right/remove_dynamic_attribute_spec.rb",
77
+ "spec/datts_right/where_dynamic_attribute_spec.rb",
63
78
  "spec/datts_right_spec.rb",
64
79
  "spec/spec_helper.rb"
65
80
  ]
@@ -275,6 +290,12 @@ Gem::Specification.new do |s|
275
290
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
276
291
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
277
292
  s.add_development_dependency(%q<rcov>, [">= 0"])
293
+ s.add_development_dependency(%q<autotest>, [">= 0"])
294
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
295
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
296
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
297
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
298
+ s.add_development_dependency(%q<rcov>, [">= 0"])
278
299
  else
279
300
  s.add_dependency(%q<datts_right>, [">= 0"])
280
301
  s.add_dependency(%q<rails>, [">= 3.0.0"])
@@ -483,6 +504,12 @@ Gem::Specification.new do |s|
483
504
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
484
505
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
485
506
  s.add_dependency(%q<rcov>, [">= 0"])
507
+ s.add_dependency(%q<autotest>, [">= 0"])
508
+ s.add_dependency(%q<sqlite3>, [">= 0"])
509
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
510
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
511
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
512
+ s.add_dependency(%q<rcov>, [">= 0"])
486
513
  end
487
514
  else
488
515
  s.add_dependency(%q<datts_right>, [">= 0"])
@@ -692,6 +719,12 @@ Gem::Specification.new do |s|
692
719
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
693
720
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
694
721
  s.add_dependency(%q<rcov>, [">= 0"])
722
+ s.add_dependency(%q<autotest>, [">= 0"])
723
+ s.add_dependency(%q<sqlite3>, [">= 0"])
724
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
725
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
726
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
727
+ s.add_dependency(%q<rcov>, [">= 0"])
695
728
  end
696
729
  end
697
730
 
data/lib/datts_right.rb CHANGED
@@ -2,5 +2,6 @@ require 'datts_right/base'
2
2
  require 'datts_right/instance_methods'
3
3
  require 'datts_right/dynamic_attribute'
4
4
  require 'datts_right/dynamic_attribute_definition'
5
+ require 'datts_right/errors'
5
6
 
6
7
  ActiveRecord::Base.extend DattsRight::Base
@@ -0,0 +1,13 @@
1
+ module DattsRight
2
+ class DattsRightError < StandardError
3
+ end
4
+
5
+ class NoDefinitionError < DattsRightError
6
+ end
7
+
8
+ class AlreadyDefined < DattsRightError
9
+ end
10
+
11
+ class NotDefinedError < DattsRightError
12
+ end
13
+ end
@@ -119,6 +119,32 @@ module DattsRight
119
119
  end
120
120
  end
121
121
 
122
+ def add_definition(key, value)
123
+ key = key.to_sym
124
+ if dynamic_attributes_options[:definition]
125
+ if definition[key]
126
+ raise AlreadyDefined, "#{key} is already defined"
127
+ else
128
+ definition.merge!({key => value})
129
+ end
130
+ else
131
+ raise NoDefinitionError
132
+ end
133
+ end
134
+
135
+ def remove_definition(key)
136
+ key = key.to_sym
137
+ if dynamic_attributes_options[:definition]
138
+ if definition && definition[key]
139
+ definition.delete(key)
140
+ else
141
+ raise NotDefinedError, "#{key} is not defined"
142
+ end
143
+ else
144
+ raise NoDefinitionError
145
+ end
146
+ end
147
+
122
148
  private
123
149
 
124
150
  # Called after validation on update so that dynamic attributes behave
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe DattsRight, ".add_definition(key, value)" do
4
+ before do
5
+ reset_database
6
+ end
7
+
8
+ it "should add a definition to the existing definition" do
9
+ c = Category.create
10
+ c.definition = {:robot => {:object_type => "string"}}
11
+ c.save
12
+ c.add_definition(:name, :object_type => "string", :description => "This is great")
13
+ c.save
14
+ c.definition[:name].should == {:object_type => "string", :description => "This is great"}
15
+ end
16
+
17
+ it "should raise DattsRight::AttributeAlreadyExists if the attribute is already there" do
18
+ c = Category.create
19
+ c.definition = {:robot => {:object_type => "string"}}
20
+ c.save
21
+ lambda {c.add_definition(:robot, "whatever")}.should raise_error(DattsRight::AlreadyDefined, "robot is already defined")
22
+ end
23
+
24
+ it "should raise NoMethodError if it doesn't have definition => true" do
25
+ lambda {Page.create.add_definition(:fake, :object_type => "string")}.should raise_error(DattsRight::NoDefinitionError)
26
+ end
27
+ 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
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe DattsRight, "on the definition" do
4
+ it "should not be created if it is not defined" do
5
+ Page.create.dynamic_attribute_definition.should be_nil
6
+ end
7
+ end
@@ -0,0 +1,91 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe DattsRight, "on dynamic find_by_dynamic_attribute methods" do
4
+ before do
5
+ reset_database
6
+ @page = Page.create
7
+ end
8
+
9
+ it "should be aliased by find_by_datt" do
10
+ @page.add_dynamic_attribute(:price, "integer")
11
+ @page.write_dynamic_attribute :price, 400
12
+ @page.save
13
+ Page.find_by_datt_price(400).should == Page.find_by_dynamic_attribute_price(400)
14
+ end
15
+
16
+ it "should be able to return single records" do
17
+ @page.add_dynamic_attribute(:price, "integer")
18
+ @page.write_dynamic_attribute :price, 400
19
+ @page.save
20
+
21
+ @page_2 = Page.create
22
+ @page_2.add_dynamic_attribute(:price, "integer")
23
+ @page_2.write_dynamic_attribute :price, 500
24
+ @page_2.save
25
+
26
+ @results = Page.find_by_dynamic_attribute_price(400)
27
+ @results.should == @page
28
+ @results.should_not == @page_2
29
+ end
30
+
31
+ it "should be able to return all matching records" do
32
+ @page.add_dynamic_attribute(:price, "integer")
33
+ @page.write_dynamic_attribute :price, 400
34
+ @page.save
35
+
36
+ @page_2 = Page.create
37
+ @page_2.add_dynamic_attribute(:price, "integer")
38
+ @page_2.write_dynamic_attribute :price, 500
39
+ @page_2.save
40
+
41
+ @page_3 = Page.create
42
+ @page_3.add_dynamic_attribute(:price, "integer")
43
+ @page_3.write_dynamic_attribute :price, 400
44
+ @page_3.save
45
+
46
+ @results = Page.find_all_by_dynamic_attribute_price(400)
47
+ @results.should include(@page)
48
+ @results.should_not include(@page_2)
49
+ @results.should include(@page_3)
50
+ end
51
+
52
+ it "should still allow raising of NoMethodError if the original attribute does not exist" do
53
+ lambda { Page.find_by_faker("hi") }.should raise_error(NoMethodError)
54
+ end
55
+
56
+ it "should be able to return the last record" do
57
+ @page.add_dynamic_attribute(:price, "integer")
58
+ @page.write_dynamic_attribute :price, 400
59
+ @page.save
60
+
61
+ @page_2 = Page.create
62
+ @page_2.add_dynamic_attribute(:price, "integer")
63
+ @page_2.write_dynamic_attribute :price, 400
64
+ @page_2.save
65
+
66
+ Page.find_last_by_dynamic_attribute_price(400) == @page_2
67
+ end
68
+
69
+ it "should allow normal attributes to work" do
70
+ @page.name = "Roland"
71
+ @page.save
72
+
73
+ Page.find_by_name("Roland").should == @page
74
+ end
75
+
76
+ it "should allow chaining" do
77
+ @page.add_dynamic_attribute(:price, "integer")
78
+ @page.name = "fixed"
79
+ @page.write_dynamic_attribute :price, 400
80
+ @page.save
81
+
82
+ @page_2 = Page.create
83
+ @page_2.add_dynamic_attribute(:price, "integer")
84
+ @page_2.write_dynamic_attribute :price, 500
85
+ @page_2.save
86
+
87
+ @pages = Page.where(:name => "fixed").find_by_dynamic_attribute_price(400)
88
+ @pages.should == @page
89
+ @pages.should_not == @page_2
90
+ end
91
+ end
@@ -2,11 +2,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe DattsRight, "when inheriting the definition of an association" do
4
4
  before do
5
+ reset_database
5
6
  @category = Category.create
6
7
  @category.definition = {:teaser => {:object_type => "text"}, :price => {:object_type => "integer"}}
7
8
  @category.save
8
9
  @page = Page.create :category => @category
9
10
  end
11
+
10
12
  it "should create the dynamic attributes" do
11
13
  @page.teaser = "hi"
12
14
  @page.teaser.should == "hi"
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe DattsRight, ".read_dynamic_attribute" do
4
+ it "should be aliased by read_datt" do
5
+ Page.instance_method(:read_dynamic_attribute).should == Page.instance_method(:read_datt)
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe DattsRight, ".remove_definition(key, value)" do
4
+ before do
5
+ reset_database
6
+ end
7
+
8
+ it "should remove a definition from the existing definition" do
9
+ c = Category.create
10
+ c.definition = {:robot => {:object_type => "string"}}
11
+ c.save
12
+ c.remove_definition(:robot)
13
+ c.definition[:robot].should be_nil
14
+ end
15
+
16
+ it "should raise NotDefinedError if it doesn't exist" do
17
+ lambda {Category.create.remove_definition(:robot)}.should raise_error(DattsRight::NotDefinedError, "robot is not defined")
18
+ end
19
+
20
+ it "should raise NoDefinitionError if it doesn't have definition => true" do
21
+ lambda {Page.create.remove_definition(:fake)}.should raise_error(DattsRight::NoDefinitionError)
22
+ end
23
+ end
@@ -0,0 +1,53 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe DattsRight, ".where_dynamic_attribute" do
4
+ before do
5
+ reset_database
6
+ @page = Page.create
7
+ end
8
+
9
+ it "should be aliased by where_datt" do
10
+ @page.add_dynamic_attribute(:price, "float")
11
+ @page.write_dynamic_attribute :price, 200.0
12
+ Page.where_dynamic_attribute(:price => 200.0).should == Page.where_datt(:price => 200.0)
13
+ end
14
+
15
+ it "should automatically join in the dynamic_attributes table" do
16
+ @page.add_dynamic_attribute(:price, "float")
17
+ @page.write_dynamic_attribute :price, 200.0
18
+ @page.add_dynamic_attribute(:farce, "boolean")
19
+ @page.write_dynamic_attribute :farce, true
20
+ @page.save
21
+
22
+ @page_2 = Page.create
23
+ @page_2.add_dynamic_attribute(:price, "integer")
24
+ @page_2.add_dynamic_attribute(:farce, "boolean")
25
+ @page_2.write_dynamic_attribute :farce, true
26
+ @page_2.write_dynamic_attribute :price, 1
27
+ @page_2.save
28
+
29
+ @result = Page.where_dynamic_attribute(:price => 200.0, :farce => true)
30
+ @result.should include(@page)
31
+ @result.should_not include(@page_2)
32
+ end
33
+
34
+ it "should allow chaining with where scopes" do
35
+ @page.add_dynamic_attribute(:price, "integer")
36
+ @page.name = "aardvark"
37
+ @page.write_dynamic_attribute :price, 200
38
+ @page.save
39
+
40
+ @page_2 = Page.create
41
+ @page_2.add_dynamic_attribute(:price, "integer")
42
+ @page_2.write_dynamic_attribute :price, 200
43
+ @page_2.save
44
+
45
+ @results = Page.where_dynamic_attribute(:price => 200).where(:name => "aardvark")
46
+ @results.should include(@page)
47
+ @results.should_not include(@page_2)
48
+ end
49
+
50
+ it "should return an empty array if we're looking for a field that doesn't exist" do
51
+ Page.where_dynamic_attribute(:bogus_field => "none").should be_empty
52
+ end
53
+ end
@@ -1,7 +1,4 @@
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
5
2
 
6
3
  describe DattsRight do
7
4
  before do
@@ -9,56 +6,6 @@ describe DattsRight do
9
6
  @page = Page.create
10
7
  end
11
8
 
12
- describe ".add_dynamic_attribute(attr_key, object_type)" do
13
- it "should be aliased by add_datt" do
14
- Page.instance_method(:add_dynamic_attribute).should == Page.instance_method(:add_datt)
15
- end
16
-
17
- it "should add a dynamic attribute" do
18
- @page.add_dynamic_attribute(:rocks, "string")
19
- @page.dynamic_attribute_details(:rocks).value.should be_nil
20
- @page.add_dynamic_attribute(:rock, "string", "123")
21
- @page.read_datt(:rock).should == "123"
22
- @page.dynamic_attribute_details(:rock).value.should == "123"
23
- end
24
-
25
- it "should ignore when trying to add same attribute" do
26
- @page.add_dynamic_attribute(:rocks, "string")
27
- @page.add_dynamic_attribute(:rocks, "integer")
28
- @page.dynamic_attribute_details(:rocks).object_type.should == "string"
29
- end
30
-
31
- it "should return false if the method that is being added already exists" do
32
- @page.add_dynamic_attribute(:name, "text").should be_false
33
- end
34
-
35
- it "should not make any changes to the original attribute" do
36
- @page.update_attribute(:name, "juno")
37
- @page.add_dynamic_attribute(:name, "text")
38
- @page.name.should == "juno"
39
- end
40
- end
41
-
42
- describe ".remove_dynamic_attribute(attr_key)" do
43
- it "should be aliased by remove_datt" do
44
- Page.instance_method(:remove_dynamic_attribute).should == Page.instance_method(:remove_datt)
45
- end
46
-
47
- it "should remove the attribute completely" do
48
- @page.add_dynamic_attribute(:rocks, "string")
49
- @page.remove_dynamic_attribute(:rocks)
50
- lambda { @page.rocks }.should raise_error(NoMethodError)
51
- end
52
-
53
- it "should not explode if the attribute being removed isn't there" do
54
- @page.add_dynamic_attribute(:rocks, "string")
55
- @page.remove_dynamic_attribute(:rocks)
56
- lambda {
57
- @page.remove_dynamic_attribute(:rocks)
58
- }.should_not raise_error(NoMethodError)
59
- end
60
- end
61
-
62
9
  it "should not allow arbitrary creation of attributes" do
63
10
  lambda {
64
11
  @page.some_field = "woot"
@@ -145,97 +92,6 @@ describe DattsRight do
145
92
  @page.dynamic_attribute?(:farce).should be_true
146
93
  end
147
94
 
148
- describe ".read_dynamic_attribute" do
149
- it "should be aliased by read_datt" do
150
- Page.instance_method(:read_dynamic_attribute).should == Page.instance_method(:read_datt)
151
- end
152
- end
153
-
154
- describe "on dynamic find_by_dynamic_attribute methods" do
155
- it "should be aliased by find_by_datt" do
156
- @page.add_dynamic_attribute(:price, "integer")
157
- @page.write_dynamic_attribute :price, 400
158
- @page.save
159
- Page.find_by_datt_price(400).should == Page.find_by_dynamic_attribute_price(400)
160
- end
161
-
162
- it "should be able to return single records" do
163
- @page.add_dynamic_attribute(:price, "integer")
164
- @page.write_dynamic_attribute :price, 400
165
- @page.save
166
-
167
- @page_2 = Page.create
168
- @page_2.add_dynamic_attribute(:price, "integer")
169
- @page_2.write_dynamic_attribute :price, 500
170
- @page_2.save
171
-
172
- @results = Page.find_by_dynamic_attribute_price(400)
173
- @results.should == @page
174
- @results.should_not == @page_2
175
- end
176
-
177
- it "should be able to return all matching records" do
178
- @page.add_dynamic_attribute(:price, "integer")
179
- @page.write_dynamic_attribute :price, 400
180
- @page.save
181
-
182
- @page_2 = Page.create
183
- @page_2.add_dynamic_attribute(:price, "integer")
184
- @page_2.write_dynamic_attribute :price, 500
185
- @page_2.save
186
-
187
- @page_3 = Page.create
188
- @page_3.add_dynamic_attribute(:price, "integer")
189
- @page_3.write_dynamic_attribute :price, 400
190
- @page_3.save
191
-
192
- @results = Page.find_all_by_dynamic_attribute_price(400)
193
- @results.should include(@page)
194
- @results.should_not include(@page_2)
195
- @results.should include(@page_3)
196
- end
197
-
198
- it "should still allow raising of NoMethodError if the original attribute does not exist" do
199
- lambda { Page.find_by_faker("hi") }.should raise_error(NoMethodError)
200
- end
201
-
202
- it "should be able to return the last record" do
203
- @page.add_dynamic_attribute(:price, "integer")
204
- @page.write_dynamic_attribute :price, 400
205
- @page.save
206
-
207
- @page_2 = Page.create
208
- @page_2.add_dynamic_attribute(:price, "integer")
209
- @page_2.write_dynamic_attribute :price, 400
210
- @page_2.save
211
-
212
- Page.find_last_by_dynamic_attribute_price(400) == @page_2
213
- end
214
-
215
- it "should allow normal attributes to work" do
216
- @page.name = "Roland"
217
- @page.save
218
-
219
- Page.find_by_name("Roland").should == @page
220
- end
221
-
222
- it "should allow chaining" do
223
- @page.add_dynamic_attribute(:price, "integer")
224
- @page.name = "fixed"
225
- @page.write_dynamic_attribute :price, 400
226
- @page.save
227
-
228
- @page_2 = Page.create
229
- @page_2.add_dynamic_attribute(:price, "integer")
230
- @page_2.write_dynamic_attribute :price, 500
231
- @page_2.save
232
-
233
- @pages = Page.where(:name => "fixed").find_by_dynamic_attribute_price(400)
234
- @pages.should == @page
235
- @pages.should_not == @page_2
236
- end
237
- end
238
-
239
95
  it "should allow multiple attributes" do
240
96
  @page.add_dynamic_attribute(:price, "integer")
241
97
  @page.write_dynamic_attribute :price, 400
@@ -345,57 +201,6 @@ describe DattsRight do
345
201
  end
346
202
  end
347
203
 
348
- describe "where_dynamic_attribute" do
349
- it "should be aliased by where_datt" do
350
- @page.add_dynamic_attribute(:price, "float")
351
- @page.write_dynamic_attribute :price, 200.0
352
- Page.where_dynamic_attribute(:price => 200.0).should == Page.where_datt(:price => 200.0)
353
- end
354
-
355
- it "should automatically join in the dynamic_attributes table" do
356
- @page.add_dynamic_attribute(:price, "float")
357
- @page.write_dynamic_attribute :price, 200.0
358
- @page.add_dynamic_attribute(:farce, "boolean")
359
- @page.write_dynamic_attribute :farce, true
360
- @page.save
361
-
362
- @page_2 = Page.create
363
- @page_2.add_dynamic_attribute(:price, "integer")
364
- @page_2.add_dynamic_attribute(:farce, "boolean")
365
- @page_2.write_dynamic_attribute :farce, true
366
- @page_2.write_dynamic_attribute :price, 1
367
- @page_2.save
368
-
369
- @result = Page.where_dynamic_attribute(:price => 200.0, :farce => true)
370
- @result.should include(@page)
371
- @result.should_not include(@page_2)
372
-
373
- #@result = Page.where_dynamic_attribute("price < :price", :price => 199.0)
374
- #@result.should_not include(@page)
375
- #@result.should include(@page_2)
376
- end
377
-
378
- it "should allow chaining with where scopes" do
379
- @page.add_dynamic_attribute(:price, "integer")
380
- @page.name = "aardvark"
381
- @page.write_dynamic_attribute :price, 200
382
- @page.save
383
-
384
- @page_2 = Page.create
385
- @page_2.add_dynamic_attribute(:price, "integer")
386
- @page_2.write_dynamic_attribute :price, 200
387
- @page_2.save
388
-
389
- @results = Page.where_dynamic_attribute(:price => 200).where(:name => "aardvark")
390
- @results.should include(@page)
391
- @results.should_not include(@page_2)
392
- end
393
-
394
- it "should return an empty array if we're looking for a field that doesn't exist" do
395
- Page.where_dynamic_attribute(:bogus_field => "none").should be_empty
396
- end
397
- end
398
-
399
204
  describe ".dynamic_attribute_details(key)" do
400
205
  it "should be aliased by datt_details" do
401
206
  Page.instance_method(:dynamic_attribute_details).should == Page.instance_method(:datt_details)
@@ -438,25 +243,4 @@ describe DattsRight do
438
243
  @page.save
439
244
  @page.body.should == "dude"
440
245
  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
456
-
457
- describe "on the definition" do
458
- it "should not be created if it is not defined" do
459
- Page.create.dynamic_attribute_definition.should be_nil
460
- end
461
- end
462
246
  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: 57
4
+ hash: 55
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 19
10
- version: 0.0.19
9
+ - 20
10
+ version: 0.0.20
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ramon Tayag
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-19 00:00:00 +08:00
18
+ date: 2011-04-26 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -3124,6 +3124,96 @@ dependencies:
3124
3124
  name: rcov
3125
3125
  version_requirements: *id207
3126
3126
  prerelease: false
3127
+ - !ruby/object:Gem::Dependency
3128
+ type: :development
3129
+ requirement: &id208 !ruby/object:Gem::Requirement
3130
+ none: false
3131
+ requirements:
3132
+ - - ">="
3133
+ - !ruby/object:Gem::Version
3134
+ hash: 3
3135
+ segments:
3136
+ - 0
3137
+ version: "0"
3138
+ name: autotest
3139
+ version_requirements: *id208
3140
+ prerelease: false
3141
+ - !ruby/object:Gem::Dependency
3142
+ type: :development
3143
+ requirement: &id209 !ruby/object:Gem::Requirement
3144
+ none: false
3145
+ requirements:
3146
+ - - ">="
3147
+ - !ruby/object:Gem::Version
3148
+ hash: 3
3149
+ segments:
3150
+ - 0
3151
+ version: "0"
3152
+ name: sqlite3
3153
+ version_requirements: *id209
3154
+ prerelease: false
3155
+ - !ruby/object:Gem::Dependency
3156
+ type: :development
3157
+ requirement: &id210 !ruby/object:Gem::Requirement
3158
+ none: false
3159
+ requirements:
3160
+ - - ~>
3161
+ - !ruby/object:Gem::Version
3162
+ hash: 3
3163
+ segments:
3164
+ - 2
3165
+ - 3
3166
+ - 0
3167
+ version: 2.3.0
3168
+ name: rspec
3169
+ version_requirements: *id210
3170
+ prerelease: false
3171
+ - !ruby/object:Gem::Dependency
3172
+ type: :development
3173
+ requirement: &id211 !ruby/object:Gem::Requirement
3174
+ none: false
3175
+ requirements:
3176
+ - - ~>
3177
+ - !ruby/object:Gem::Version
3178
+ hash: 23
3179
+ segments:
3180
+ - 1
3181
+ - 0
3182
+ - 0
3183
+ version: 1.0.0
3184
+ name: bundler
3185
+ version_requirements: *id211
3186
+ prerelease: false
3187
+ - !ruby/object:Gem::Dependency
3188
+ type: :development
3189
+ requirement: &id212 !ruby/object:Gem::Requirement
3190
+ none: false
3191
+ requirements:
3192
+ - - ~>
3193
+ - !ruby/object:Gem::Version
3194
+ hash: 7
3195
+ segments:
3196
+ - 1
3197
+ - 5
3198
+ - 2
3199
+ version: 1.5.2
3200
+ name: jeweler
3201
+ version_requirements: *id212
3202
+ prerelease: false
3203
+ - !ruby/object:Gem::Dependency
3204
+ type: :development
3205
+ requirement: &id213 !ruby/object:Gem::Requirement
3206
+ none: false
3207
+ requirements:
3208
+ - - ">="
3209
+ - !ruby/object:Gem::Version
3210
+ hash: 3
3211
+ segments:
3212
+ - 0
3213
+ version: "0"
3214
+ name: rcov
3215
+ version_requirements: *id213
3216
+ prerelease: false
3127
3217
  description: Creates a separate table that saves all your dynamic attributes.
3128
3218
  email: ramon@tayag.net
3129
3219
  executables: []
@@ -3150,17 +3240,25 @@ files:
3150
3240
  - lib/datts_right/category.rb
3151
3241
  - lib/datts_right/dynamic_attribute.rb
3152
3242
  - lib/datts_right/dynamic_attribute_definition.rb
3243
+ - lib/datts_right/errors.rb
3153
3244
  - lib/datts_right/exceptions.rb
3154
3245
  - lib/datts_right/instance_methods.rb
3155
3246
  - lib/datts_right/page.rb
3156
3247
  - lib/datts_right/query_methods.rb
3157
3248
  - spec/datt_spec.rb
3249
+ - spec/datts_right/add_definition_spec.rb
3250
+ - spec/datts_right/add_dynamic_attribute_spec.rb
3158
3251
  - spec/datts_right/add_dynamic_attributes_spec.rb
3159
3252
  - spec/datts_right/attributes_spec.rb
3160
3253
  - spec/datts_right/create_definitions_spec.rb
3254
+ - spec/datts_right/definition_spec.rb
3161
3255
  - spec/datts_right/dynamic_attribute_definition_spec.rb
3256
+ - spec/datts_right/find_by_dynamic_attribute_spec.rb
3162
3257
  - spec/datts_right/inheritance_spec.rb
3258
+ - spec/datts_right/read_dynamic_attribute_spec.rb
3259
+ - spec/datts_right/remove_definition_spec.rb
3163
3260
  - spec/datts_right/remove_dynamic_attribute_spec.rb
3261
+ - spec/datts_right/where_dynamic_attribute_spec.rb
3164
3262
  - spec/datts_right_spec.rb
3165
3263
  - spec/spec_helper.rb
3166
3264
  has_rdoc: true
@@ -3199,11 +3297,18 @@ specification_version: 3
3199
3297
  summary: Allows saving of dynamic attributes in your ActiveRecord model
3200
3298
  test_files:
3201
3299
  - spec/datt_spec.rb
3300
+ - spec/datts_right/add_definition_spec.rb
3301
+ - spec/datts_right/add_dynamic_attribute_spec.rb
3202
3302
  - spec/datts_right/add_dynamic_attributes_spec.rb
3203
3303
  - spec/datts_right/attributes_spec.rb
3204
3304
  - spec/datts_right/create_definitions_spec.rb
3305
+ - spec/datts_right/definition_spec.rb
3205
3306
  - spec/datts_right/dynamic_attribute_definition_spec.rb
3307
+ - spec/datts_right/find_by_dynamic_attribute_spec.rb
3206
3308
  - spec/datts_right/inheritance_spec.rb
3309
+ - spec/datts_right/read_dynamic_attribute_spec.rb
3310
+ - spec/datts_right/remove_definition_spec.rb
3207
3311
  - spec/datts_right/remove_dynamic_attribute_spec.rb
3312
+ - spec/datts_right/where_dynamic_attribute_spec.rb
3208
3313
  - spec/datts_right_spec.rb
3209
3314
  - spec/spec_helper.rb