property_sets 0.4.0 → 0.4.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/README.rdoc CHANGED
@@ -32,6 +32,23 @@ The declared properties can then be accessed runtime via the defined association
32
32
  # Short hand for setting one or more values
33
33
  account.settings.set(:version => "v1.2", :activated => true)
34
34
 
35
+ === Validations
36
+
37
+ Property sets supports standard AR validations, although in a somewhat manual fashion.
38
+
39
+ class Account < ActiveRecord::Base
40
+ property_set :settings do
41
+ property :version, :default => "v1.0"
42
+ property :featured, :protected => true
43
+
44
+ validates_format_of :value, :with => /v\d+\.\d+/, :message => "of version is invalid",
45
+ :if => Proc.new { |r| r.name.to_sym == :version }
46
+ end
47
+ end
48
+
49
+ On +account.save+ this will result in an error record being added. You can also inspect the
50
+ setting record using +account.settings.version_record+
51
+
35
52
  === Bulk operations
36
53
 
37
54
  Stored properties can also be updated with the update_attributes and update_attributes! methods by
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -41,6 +41,10 @@ module PropertySets
41
41
  lookup(key).value
42
42
  end
43
43
 
44
+ define_method "#{key}_record" do
45
+ lookup(key)
46
+ end
47
+
44
48
  define_method "protected?" do |arg|
45
49
  lookup(arg).protected?
46
50
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{property_sets}
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Morten Primdahl"]
12
- s.date = %q{2011-03-07}
12
+ s.date = %q{2011-03-17}
13
13
  s.description = %q{This gem is an ActiveRecord extension which provides a convenient interface for managing per row properties}
14
14
  s.email = %q{morten@zendesk.com}
15
15
  s.extra_rdoc_files = [
data/test/helper.rb CHANGED
@@ -46,6 +46,12 @@ class Account < ActiveRecord::Base
46
46
  property :foo
47
47
  property :bar
48
48
  end
49
-
50
49
  accepts_nested_attributes_for :texts
50
+
51
+ property_set :validations do
52
+ property :validated
53
+ property :regular
54
+
55
+ validates_format_of :value, :with => /\d+/, :message => "BEEP", :if => lambda { |r| r.name.to_sym == :validated }
56
+ end
51
57
  end
data/test/schema.rb CHANGED
@@ -19,6 +19,16 @@ ActiveRecord::Schema.define(:version => 1) do
19
19
 
20
20
  add_index :account_texts, [ :account_id, :name ], :unique => true
21
21
 
22
+ create_table "account_validations", :force => true do |t|
23
+ t.integer "account_id"
24
+ t.string "name"
25
+ t.string "value"
26
+ t.datetime "created_at"
27
+ t.datetime "updated_at"
28
+ end
29
+
30
+ add_index :account_validations, [ :account_id, :name ], :unique => true
31
+
22
32
  create_table "accounts", :force => true do |t|
23
33
  t.string "name"
24
34
  t.datetime "created_at"
@@ -15,7 +15,7 @@ class TestPropertySets < ActiveSupport::TestCase
15
15
  end
16
16
 
17
17
  should "register the property sets used on a class" do
18
- assert_equal [ :settings, :texts ], Account.property_set_index
18
+ assert_equal [ :settings, :texts, :validations ], Account.property_set_index
19
19
  end
20
20
 
21
21
  should "support protecting attributes" do
@@ -98,6 +98,16 @@ class TestPropertySets < ActiveSupport::TestCase
98
98
  assert record.account.id == @account.id
99
99
  end
100
100
 
101
+ context "validations" do
102
+ should "add an error when violated" do
103
+ @account.validations.validated = "hello"
104
+ assert_equal "Value BEEP", @account.validations.first.errors.full_messages.first
105
+ assert_equal "Value BEEP", @account.validations.validated_record.errors.full_messages.first
106
+ assert_equal false, @account.save
107
+ assert_equal "Validations is invalid", @account.errors.full_messages.first
108
+ end
109
+ end
110
+
101
111
  context "#set" do
102
112
  should "support writing multiple values to the association" do
103
113
  assert !@account.settings.foo?
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: property_sets
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Morten Primdahl
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-07 00:00:00 -08:00
18
+ date: 2011-03-17 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency