property 0.9.1 → 1.0.0
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/.gitignore +1 -0
- data/History.txt +19 -3
- data/README.rdoc +51 -6
- data/lib/property.rb +4 -2
- data/lib/property/attribute.rb +14 -7
- data/lib/property/base.rb +16 -0
- data/lib/property/column.rb +13 -1
- data/lib/property/declaration.rb +48 -26
- data/lib/property/error.rb +4 -0
- data/lib/property/index.rb +104 -29
- data/lib/property/properties.rb +7 -1
- data/lib/property/redefined_method_error.rb +8 -0
- data/lib/property/redefined_property_error.rb +8 -0
- data/lib/property/role.rb +30 -0
- data/lib/property/{behavior.rb → role_module.rb} +67 -35
- data/lib/property/schema.rb +76 -32
- data/lib/property/stored_column.rb +30 -0
- data/lib/property/stored_role.rb +101 -0
- data/property.gemspec +20 -5
- data/test/fixtures.rb +39 -1
- data/test/shoulda_macros/index.rb +95 -0
- data/test/shoulda_macros/role.rb +237 -0
- data/test/shoulda_macros/serialization.rb +1 -1
- data/test/test_helper.rb +2 -0
- data/test/unit/property/base_test.rb +80 -0
- data/test/unit/property/declaration_test.rb +89 -30
- data/test/unit/property/index_foreign_test.rb +2 -2
- data/test/unit/property/index_simple_test.rb +17 -4
- data/test/unit/property/role_test.rb +78 -0
- data/test/unit/property/stored_role_test.rb +84 -0
- data/test/unit/property/validation_test.rb +26 -4
- metadata +22 -7
- data/test/unit/property/behavior_test.rb +0 -146
@@ -17,15 +17,37 @@ class ValidationTest < Test::Unit::TestCase
|
|
17
17
|
context 'without a property column' do
|
18
18
|
should 'raise ActiveRecord::UnknownAttributeError when using attributes=' do
|
19
19
|
assert_raise(ActiveRecord::UnknownAttributeError) do
|
20
|
-
subject.update_attributes('
|
20
|
+
subject.update_attributes('infamous' => 'dictator')
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
should 'set an error message on the property when set directly' do
|
25
|
-
subject.prop['
|
25
|
+
subject.prop['infamous'] = 'dictator'
|
26
26
|
assert !subject.save
|
27
|
-
|
28
|
-
|
27
|
+
assert_equal subject.errors['infamous'], 'property not declared'
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with dirty' do
|
31
|
+
should 'validate if property was not changed' do
|
32
|
+
subject.prop.instance_eval do
|
33
|
+
self['infamous'] = 'dictator'
|
34
|
+
@original_hash['infamous'] = 'dictator'
|
35
|
+
end
|
36
|
+
|
37
|
+
assert subject.update_attributes('boat' => 'Tiranic')
|
38
|
+
|
39
|
+
# value should not be removed
|
40
|
+
assert_equal 'dictator', subject.prop['infamous']
|
41
|
+
end
|
42
|
+
|
43
|
+
should 'validate if no property was changed' do
|
44
|
+
subject.prop.instance_eval do
|
45
|
+
self['infamous'] = 'dictator' # simulate legacy value
|
46
|
+
@original_hash = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
assert subject.valid?
|
50
|
+
end
|
29
51
|
end
|
30
52
|
end
|
31
53
|
|
metadata
CHANGED
@@ -3,10 +3,10 @@ name: property
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
-
- 0
|
7
|
-
- 9
|
8
6
|
- 1
|
9
|
-
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Renaud Kern
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-05-27 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -59,30 +59,41 @@ files:
|
|
59
59
|
- generators/property/property_generator.rb
|
60
60
|
- lib/property.rb
|
61
61
|
- lib/property/attribute.rb
|
62
|
-
- lib/property/
|
62
|
+
- lib/property/base.rb
|
63
63
|
- lib/property/column.rb
|
64
64
|
- lib/property/core_ext/time.rb
|
65
65
|
- lib/property/db.rb
|
66
66
|
- lib/property/declaration.rb
|
67
67
|
- lib/property/dirty.rb
|
68
|
+
- lib/property/error.rb
|
68
69
|
- lib/property/index.rb
|
69
70
|
- lib/property/properties.rb
|
71
|
+
- lib/property/redefined_method_error.rb
|
72
|
+
- lib/property/redefined_property_error.rb
|
73
|
+
- lib/property/role.rb
|
74
|
+
- lib/property/role_module.rb
|
70
75
|
- lib/property/schema.rb
|
71
76
|
- lib/property/serialization/json.rb
|
72
77
|
- lib/property/serialization/marshal.rb
|
73
78
|
- lib/property/serialization/yaml.rb
|
79
|
+
- lib/property/stored_column.rb
|
80
|
+
- lib/property/stored_role.rb
|
74
81
|
- property.gemspec
|
75
82
|
- test/fixtures.rb
|
83
|
+
- test/shoulda_macros/index.rb
|
84
|
+
- test/shoulda_macros/role.rb
|
76
85
|
- test/shoulda_macros/serialization.rb
|
77
86
|
- test/test_helper.rb
|
78
87
|
- test/unit/property/attribute_test.rb
|
79
|
-
- test/unit/property/
|
88
|
+
- test/unit/property/base_test.rb
|
80
89
|
- test/unit/property/declaration_test.rb
|
81
90
|
- test/unit/property/dirty_test.rb
|
82
91
|
- test/unit/property/index_complex_test.rb
|
83
92
|
- test/unit/property/index_custom_test.rb
|
84
93
|
- test/unit/property/index_foreign_test.rb
|
85
94
|
- test/unit/property/index_simple_test.rb
|
95
|
+
- test/unit/property/role_test.rb
|
96
|
+
- test/unit/property/stored_role_test.rb
|
86
97
|
- test/unit/property/validation_test.rb
|
87
98
|
- test/unit/serialization/json_test.rb
|
88
99
|
- test/unit/serialization/marshal_test.rb
|
@@ -119,16 +130,20 @@ specification_version: 3
|
|
119
130
|
summary: model properties wrap into a single database column
|
120
131
|
test_files:
|
121
132
|
- test/fixtures.rb
|
133
|
+
- test/shoulda_macros/index.rb
|
134
|
+
- test/shoulda_macros/role.rb
|
122
135
|
- test/shoulda_macros/serialization.rb
|
123
136
|
- test/test_helper.rb
|
124
137
|
- test/unit/property/attribute_test.rb
|
125
|
-
- test/unit/property/
|
138
|
+
- test/unit/property/base_test.rb
|
126
139
|
- test/unit/property/declaration_test.rb
|
127
140
|
- test/unit/property/dirty_test.rb
|
128
141
|
- test/unit/property/index_complex_test.rb
|
129
142
|
- test/unit/property/index_custom_test.rb
|
130
143
|
- test/unit/property/index_foreign_test.rb
|
131
144
|
- test/unit/property/index_simple_test.rb
|
145
|
+
- test/unit/property/role_test.rb
|
146
|
+
- test/unit/property/stored_role_test.rb
|
132
147
|
- test/unit/property/validation_test.rb
|
133
148
|
- test/unit/serialization/json_test.rb
|
134
149
|
- test/unit/serialization/marshal_test.rb
|
@@ -1,146 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'fixtures'
|
3
|
-
|
4
|
-
class BehaviorTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
context 'A Behavior' do
|
7
|
-
subject { Property::Behavior.new('Foobar') }
|
8
|
-
|
9
|
-
should 'allow string columns' do
|
10
|
-
subject.property.string('weapon')
|
11
|
-
column = subject.columns['weapon']
|
12
|
-
assert_equal 'weapon', column.name
|
13
|
-
assert_equal String, column.klass
|
14
|
-
assert_equal :string, column.type
|
15
|
-
end
|
16
|
-
|
17
|
-
should 'treat symbol keys as strings' do
|
18
|
-
subject.property.string(:weapon)
|
19
|
-
column = subject.columns['weapon']
|
20
|
-
assert_equal 'weapon', column.name
|
21
|
-
assert_equal String, column.klass
|
22
|
-
assert_equal :string, column.type
|
23
|
-
end
|
24
|
-
|
25
|
-
should 'allow integer columns' do
|
26
|
-
subject.property.integer('indestructible')
|
27
|
-
column = subject.columns['indestructible']
|
28
|
-
assert_equal 'indestructible', column.name
|
29
|
-
assert_equal Fixnum, column.klass
|
30
|
-
assert_equal :integer, column.type
|
31
|
-
end
|
32
|
-
|
33
|
-
should 'allow float columns' do
|
34
|
-
subject.property.float('boat')
|
35
|
-
column = subject.columns['boat']
|
36
|
-
assert_equal 'boat', column.name
|
37
|
-
assert_equal Float, column.klass
|
38
|
-
assert_equal :float, column.type
|
39
|
-
end
|
40
|
-
|
41
|
-
should 'allow datetime columns' do
|
42
|
-
subject.property.datetime('time_weapon')
|
43
|
-
column = subject.columns['time_weapon']
|
44
|
-
assert_equal 'time_weapon', column.name
|
45
|
-
assert_equal Time, column.klass
|
46
|
-
assert_equal :datetime, column.type
|
47
|
-
end
|
48
|
-
|
49
|
-
should 'allow default value option' do
|
50
|
-
subject.property.integer('force', :default => 10)
|
51
|
-
column = subject.columns['force']
|
52
|
-
assert_equal 10, column.default
|
53
|
-
end
|
54
|
-
|
55
|
-
should 'allow index option' do
|
56
|
-
subject.property.string('rolodex', :index => true)
|
57
|
-
column = subject.columns['rolodex']
|
58
|
-
assert column.indexed?
|
59
|
-
end
|
60
|
-
|
61
|
-
should 'return a list of indices on indices' do
|
62
|
-
subject.property.string('rolodex', :index => true)
|
63
|
-
subject.property.integer('foobar', :index => true)
|
64
|
-
assert_equal %w{integer string}, subject.indices.map {|i| i[0].to_s }.sort
|
65
|
-
end
|
66
|
-
end # A Behavior
|
67
|
-
|
68
|
-
context 'Adding a behavior' do
|
69
|
-
setup do
|
70
|
-
@poet = Property::Behavior.new('Poet') do |p|
|
71
|
-
p.string 'poem', :default => :muse
|
72
|
-
|
73
|
-
p.actions do
|
74
|
-
def muse
|
75
|
-
'I am your muse'
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'to a class' do
|
82
|
-
setup do
|
83
|
-
@parent = Class.new(ActiveRecord::Base) do
|
84
|
-
set_table_name :dummies
|
85
|
-
include Property
|
86
|
-
property.string 'name'
|
87
|
-
end
|
88
|
-
|
89
|
-
@klass = Class.new(@parent)
|
90
|
-
end
|
91
|
-
|
92
|
-
should 'propagate definitions to child' do
|
93
|
-
@parent.behave_like @poet
|
94
|
-
assert_equal %w{name poem}, @klass.schema.column_names.sort
|
95
|
-
end
|
96
|
-
|
97
|
-
should 'raise an exception if class contains same definitions' do
|
98
|
-
@parent.property.string 'poem'
|
99
|
-
assert_raise(TypeError) { @parent.behave_like @poet }
|
100
|
-
end
|
101
|
-
|
102
|
-
should 'not raise an exception on double inclusion' do
|
103
|
-
@parent.behave_like @poet
|
104
|
-
assert_nothing_raised { @parent.behave_like @poet }
|
105
|
-
end
|
106
|
-
|
107
|
-
should 'add accessor methods to child' do
|
108
|
-
subject = @klass.new
|
109
|
-
assert_raises(NoMethodError) { subject.poem = 'Poe'}
|
110
|
-
@parent.behave_like @poet
|
111
|
-
|
112
|
-
assert_nothing_raised { subject.poem = 'Poe'}
|
113
|
-
end
|
114
|
-
|
115
|
-
should 'add behavior methods to child' do
|
116
|
-
subject = @klass.new
|
117
|
-
assert_raises(NoMethodError) { subject.muse }
|
118
|
-
@parent.behave_like @poet
|
119
|
-
|
120
|
-
assert_nothing_raised { subject.muse }
|
121
|
-
end
|
122
|
-
|
123
|
-
should 'use behavior methos for defaults' do
|
124
|
-
subject = @klass.new
|
125
|
-
@parent.behave_like @poet
|
126
|
-
assert subject.save
|
127
|
-
assert_equal 'I am your muse', subject.poem
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
context 'to a parent class' do
|
132
|
-
end
|
133
|
-
|
134
|
-
context 'to an instance' do
|
135
|
-
subject { Developer.new }
|
136
|
-
|
137
|
-
setup do
|
138
|
-
subject.behave_like @poet
|
139
|
-
end
|
140
|
-
|
141
|
-
should 'merge property definitions' do
|
142
|
-
assert_equal %w{age first_name language last_name poem}, subject.schema.column_names.sort
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|