json_record 1.0.0 → 1.0.1

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/Rakefile CHANGED
@@ -29,12 +29,12 @@ begin
29
29
  require 'jeweler'
30
30
  Jeweler::Tasks.new do |gem|
31
31
  gem.name = "json_record"
32
- gem.summary = %Q{ActiveRecord support for mapping complex documents within a single RDBMS record via JSON serialization.}
32
+ gem.summary = %Q{ActiveRecord support for mapping complex documents in a single RDBMS row via JSON serialization.}
33
33
  gem.email = "brian@embellishedvisions.com"
34
34
  gem.homepage = "http://github.com/bdurand/json_record"
35
35
  gem.authors = ["Brian Durand"]
36
36
 
37
- gem.add_dependency('activerecord', '>= 2.2.2', '< 3.0')
37
+ gem.add_dependency('activerecord', '>= 2.2.2')
38
38
  gem.add_development_dependency('rspec', '>= 1.2.9')
39
39
  gem.add_development_dependency('jeweler')
40
40
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
data/json_record.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{json_record}
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian Durand"]
12
- s.date = %q{2010-02-07}
12
+ s.date = %q{2010-02-16}
13
13
  s.email = %q{brian@embellishedvisions.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.rdoc"
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
40
40
  s.rdoc_options = ["--charset=UTF-8"]
41
41
  s.require_paths = ["lib"]
42
42
  s.rubygems_version = %q{1.3.5}
43
- s.summary = %q{ActiveRecord support for mapping complex documents within a single RDBMS record via JSON serialization.}
43
+ s.summary = %q{ActiveRecord support for mapping complex documents in a single RDBMS row via JSON serialization.}
44
44
  s.test_files = [
45
45
  "spec/embedded_document_array_spec.rb",
46
46
  "spec/embedded_document_spec.rb",
@@ -55,16 +55,16 @@ Gem::Specification.new do |s|
55
55
  s.specification_version = 3
56
56
 
57
57
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
58
- s.add_runtime_dependency(%q<activerecord>, [">= 2.2.2", "< 3.0"])
58
+ s.add_runtime_dependency(%q<activerecord>, [">= 2.2.2"])
59
59
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
60
60
  s.add_development_dependency(%q<jeweler>, [">= 0"])
61
61
  else
62
- s.add_dependency(%q<activerecord>, [">= 2.2.2", "< 3.0"])
62
+ s.add_dependency(%q<activerecord>, [">= 2.2.2"])
63
63
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
64
64
  s.add_dependency(%q<jeweler>, [">= 0"])
65
65
  end
66
66
  else
67
- s.add_dependency(%q<activerecord>, [">= 2.2.2", "< 3.0"])
67
+ s.add_dependency(%q<activerecord>, [">= 2.2.2"])
68
68
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
69
69
  s.add_dependency(%q<jeweler>, [">= 0"])
70
70
  end
@@ -45,20 +45,19 @@ module JsonRecord
45
45
  include ActiveRecord::Validations
46
46
  include AttributeMethods
47
47
 
48
+ write_inheritable_attribute(:schema, Schema.new(self, nil))
48
49
  class_inheritable_reader :schema
49
50
 
50
51
  class << self
51
52
  # Define a field for the schema. This is a shortcut for calling schema.key.
52
53
  # See Schema#key for details.
53
54
  def key (name, *args)
54
- write_inheritable_attribute(:schema, Schema.new(self, nil)) unless schema
55
55
  schema.key(name, *args)
56
56
  end
57
57
 
58
58
  # Define a multivalued field for the schema. This is a shortcut for calling schema.many.
59
59
  # See Schema#many for details.
60
60
  def many (name, *args)
61
- write_inheritable_attribute(:schema, Schema.new(self, nil)) unless schema
62
61
  schema.many(name, *args)
63
62
  end
64
63
  end
@@ -117,6 +116,10 @@ module JsonRecord
117
116
  attributes.hash + parent.hash
118
117
  end
119
118
 
119
+ def inspect
120
+ "#<#{self.class.name} #{attributes.inspect}>"
121
+ end
122
+
120
123
  protected
121
124
 
122
125
  def json_attributes
data/lib/json_record.rb CHANGED
@@ -11,10 +11,10 @@ unless defined?(Boolean)
11
11
  end
12
12
  end
13
13
 
14
+ require File.expand_path(File.join(File.dirname(__FILE__), 'json_record', 'schema'))
14
15
  require File.expand_path(File.join(File.dirname(__FILE__), 'json_record', 'attribute_methods'))
15
16
  require File.expand_path(File.join(File.dirname(__FILE__), 'json_record', 'embedded_document'))
16
17
  require File.expand_path(File.join(File.dirname(__FILE__), 'json_record', 'embedded_document_array'))
17
18
  require File.expand_path(File.join(File.dirname(__FILE__), 'json_record', 'field_definition'))
18
19
  require File.expand_path(File.join(File.dirname(__FILE__), 'json_record', 'json_field'))
19
- require File.expand_path(File.join(File.dirname(__FILE__), 'json_record', 'schema'))
20
20
  require File.expand_path(File.join(File.dirname(__FILE__), 'json_record', 'serialized'))
@@ -237,7 +237,7 @@ describe JsonRecord::Serialized do
237
237
  model.name_change.should == ["test name", "new name"]
238
238
  model.name = "test name"
239
239
  model.changes.should == {"value" => [0, 1]}
240
- model.name_changed?.should == false
240
+ model.name_changed?.should be_blank
241
241
  model.name_was.should == "test name"
242
242
  model.name_change.should == nil
243
243
  end
@@ -245,7 +245,7 @@ describe JsonRecord::Serialized do
245
245
  it "should validate the presence of a json attribute" do
246
246
  model = JsonRecord::Test::Model.new
247
247
  model.valid?.should == false
248
- model.errors.on(:name).should_not == nil
248
+ model.errors[:name].should_not be_blank
249
249
  model.name = "woo"
250
250
  model.valid?.should == true
251
251
  end
@@ -253,16 +253,16 @@ describe JsonRecord::Serialized do
253
253
  it "should validate the length of a json attribute" do
254
254
  model = JsonRecord::Test::Model.new(:name => "this name value is way too long", :field_4 => "a", :field_5 => "b")
255
255
  model.valid?.should == false
256
- model.errors.on(:name).should_not == nil
257
- model.errors.on(:field_4).should_not == nil
258
- model.errors.on(:field_5).should_not == nil
256
+ model.errors[:name].should_not be_blank
257
+ model.errors[:field_4].should_not be_blank
258
+ model.errors[:field_5].should_not be_blank
259
259
  model.name = "shorter name"
260
260
  model.field_4 = "a much longer name that won't fit"
261
261
  model.field_5 = "a much longer name that will fit because it is OK"
262
262
  model.valid?.should == false
263
- model.errors.on(:name).should == nil
264
- model.errors.on(:field_4).should_not == nil
265
- model.errors.on(:field_5).should == nil
263
+ model.errors[:name].should be_blank
264
+ model.errors[:field_4].should_not be_blank
265
+ model.errors[:field_5].should be_blank
266
266
  model.field_4 = "just right"
267
267
  model.valid?.should == true
268
268
  end
@@ -270,11 +270,11 @@ describe JsonRecord::Serialized do
270
270
  it "should validate the type of a json attribute" do
271
271
  model = JsonRecord::Test::Model.new(:name => "test name", :value => "purple", :price => "free", :when => "2010-40-52", :verified_at => "2010-40-50T00:00:00", :viewed_at => "2010-02-01T00:90:00")
272
272
  model.valid?.should == false
273
- model.errors.on(:value).should_not == nil
274
- model.errors.on(:price).should_not == nil
275
- model.errors.on(:when).should_not == nil
276
- model.errors.on(:verified_at).should_not == nil
277
- model.errors.on(:viewed_at).should_not == nil
273
+ model.errors[:value].should_not be_blank
274
+ model.errors[:price].should_not be_blank
275
+ model.errors[:when].should_not be_blank
276
+ model.errors[:verified_at].should_not be_blank
277
+ model.errors[:viewed_at].should_not be_blank
278
278
  model.value = "1"
279
279
  model.price = "100"
280
280
  model.when = "2010-02-01"
@@ -286,7 +286,7 @@ describe JsonRecord::Serialized do
286
286
  it "should validate that a json attribute is in a range" do
287
287
  model = JsonRecord::Test::Model.new(:name => "test name", :field_3 => "Z")
288
288
  model.valid?.should == false
289
- model.errors.on(:field_3).should_not == nil
289
+ model.errors[:field_3].should_not be_blank
290
290
  model.field_3 = "B"
291
291
  model.valid?.should == true
292
292
  end
@@ -294,7 +294,7 @@ describe JsonRecord::Serialized do
294
294
  it "should validate the format of a json attribute" do
295
295
  model = JsonRecord::Test::Model.new(:name => "test name", :field_2 => "ABC")
296
296
  model.valid?.should == false
297
- model.errors.on(:field_2).should_not == nil
297
+ model.errors[:field_2].should_not be_blank
298
298
  model.field_2 = "abc"
299
299
  model.valid?.should == true
300
300
  end
@@ -391,15 +391,15 @@ describe JsonRecord::Serialized do
391
391
  it "should validate uniqueness of embedded documents" do
392
392
  model = JsonRecord::Test::Model.new(:name => "test", :traits => [{:name => "n1", :value => "v1"}, {:name => "n1", :value => "v2"}])
393
393
  model.valid?.should == false
394
- model.errors.on(:traits).should_not == nil
395
- model.traits.first.errors.on(:name).should == nil
396
- model.traits.last.errors.on(:name).should_not == nil
394
+ model.errors[:traits].should_not be_blank
395
+ model.traits.first.errors[:name].should be_blank
396
+ model.traits.last.errors[:name].should_not be_blank
397
397
 
398
398
  model.traits.last.name = "n2"
399
399
  model.valid?.should == true
400
- model.errors.on(:traits).should == nil
401
- model.traits.first.errors.on(:name).should == nil
402
- model.traits.last.errors.on(:name).should == nil
400
+ model.errors[:traits].should be_blank
401
+ model.traits.first.errors[:name].should be_blank
402
+ model.traits.last.errors[:name].should be_blank
403
403
  end
404
404
 
405
405
  it "should perform validations on embedded documents" do
@@ -408,23 +408,23 @@ describe JsonRecord::Serialized do
408
408
  trait = model.traits.build(:value => "v1")
409
409
  subtrait = trait.sub_traits.build(:name => "s1", :count => "plaid")
410
410
  model.valid?.should == false
411
- model.errors.on(:primary_trait).should_not == nil
412
- model.errors.on(:traits).should_not == nil
413
- model.primary_trait.errors.on(:name).should_not == nil
414
- trait.errors.on(:name).should_not == nil
415
- trait.errors.on(:sub_traits).should_not == nil
416
- subtrait.errors.on(:count).should_not == nil
411
+ model.errors[:primary_trait].should_not be_blank
412
+ model.errors[:traits].should_not be_blank
413
+ model.primary_trait.errors[:name].should_not be_blank
414
+ trait.errors[:name].should_not be_blank
415
+ trait.errors[:sub_traits].should_not be_blank
416
+ subtrait.errors[:count].should_not be_blank
417
417
 
418
418
  model.primary_trait.name = "p1"
419
419
  trait.name = "n1"
420
420
  subtrait.count = 1
421
421
  model.valid?.should == true
422
- model.errors.on(:primary_trait).should == nil
423
- model.errors.on(:traits).should == nil
424
- model.primary_trait.errors.on(:name).should == nil
425
- trait.errors.on(:name).should == nil
426
- trait.errors.on(:sub_traits).should == nil
427
- subtrait.errors.on(:count).should == nil
422
+ model.errors[:primary_trait].should be_blank
423
+ model.errors[:traits].should be_blank
424
+ model.primary_trait.errors[:name].should be_blank
425
+ trait.errors[:name].should be_blank
426
+ trait.errors[:sub_traits].should be_blank
427
+ subtrait.errors[:count].should be_blank
428
428
  end
429
429
 
430
430
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-07 00:00:00 -06:00
12
+ date: 2010-02-16 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -21,9 +21,6 @@ dependencies:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
23
  version: 2.2.2
24
- - - <
25
- - !ruby/object:Gem::Version
26
- version: "3.0"
27
24
  version:
28
25
  - !ruby/object:Gem::Dependency
29
26
  name: rspec
@@ -101,7 +98,7 @@ rubyforge_project:
101
98
  rubygems_version: 1.3.5
102
99
  signing_key:
103
100
  specification_version: 3
104
- summary: ActiveRecord support for mapping complex documents within a single RDBMS record via JSON serialization.
101
+ summary: ActiveRecord support for mapping complex documents in a single RDBMS row via JSON serialization.
105
102
  test_files:
106
103
  - spec/embedded_document_array_spec.rb
107
104
  - spec/embedded_document_spec.rb