property_sets 2.5.0 → 2.6.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.
- checksums.yaml +4 -4
- data/lib/property_sets/active_record_extension.rb +11 -33
- data/lib/property_sets/casting.rb +23 -13
- data/lib/property_sets/property_set_model.rb +4 -6
- data/lib/property_sets/version.rb +1 -1
- metadata +13 -55
- data/.document +0 -5
- data/.gitignore +0 -10
- data/.travis.yml +0 -21
- data/Appraisals +0 -20
- data/Gemfile +0 -16
- data/LICENSE +0 -176
- data/README.md +0 -145
- data/Rakefile +0 -14
- data/benchmark/read.rb +0 -82
- data/gemfiles/rails2.3.gemfile +0 -20
- data/gemfiles/rails3.2.gemfile +0 -19
- data/gemfiles/rails4.0.gemfile +0 -20
- data/property_sets.gemspec +0 -20
- data/test/database.rb +0 -83
- data/test/fixtures/account_settings.yml +0 -14
- data/test/fixtures/account_texts.yml +0 -4
- data/test/fixtures/accounts.yml +0 -3
- data/test/helper.rb +0 -99
- data/test/test_casting.rb +0 -38
- data/test/test_delegator.rb +0 -78
- data/test/test_property_sets.rb +0 -408
- data/test/test_view_extensions.rb +0 -198
@@ -1,198 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
-
|
3
|
-
class TestViewExtensions < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
context "property set view extensions" do
|
6
|
-
setup do
|
7
|
-
@property_set = :settings
|
8
|
-
@property = :active
|
9
|
-
@object_name = 'object_name'
|
10
|
-
@object = stub
|
11
|
-
@template = stub
|
12
|
-
@builder = ActionView::Helpers::FormBuilder.new(@object_name, @object, @template, {}, 'proc')
|
13
|
-
@proxy = @builder.property_set(@property_set)
|
14
|
-
end
|
15
|
-
|
16
|
-
should "provide a form builder proxy" do
|
17
|
-
assert @proxy.is_a?(ActionView::Helpers::FormBuilder::PropertySetFormBuilderProxy)
|
18
|
-
assert_equal @property_set, @proxy.property_set
|
19
|
-
end
|
20
|
-
|
21
|
-
should "fetch the target object when not available" do
|
22
|
-
@builder = ActionView::Helpers::FormBuilder.new(@object_name, nil, @template, {}, 'proc')
|
23
|
-
@proxy = @builder.property_set(@property_set)
|
24
|
-
|
25
|
-
@object.stubs(@property_set).returns(stub(@property => 'value'))
|
26
|
-
@template.stubs(:hidden_field)
|
27
|
-
|
28
|
-
@template.expects(:instance_variable_get).with("@#{@object_name}").returns(@object)
|
29
|
-
@proxy.hidden_field(@property)
|
30
|
-
end
|
31
|
-
|
32
|
-
context "#check_box" do
|
33
|
-
context "when called with checked true for a truth value" do
|
34
|
-
setup do
|
35
|
-
settings = stub(@property => '1', "#{@property}?".to_sym => true)
|
36
|
-
@object.stubs(@property_set).returns(settings)
|
37
|
-
end
|
38
|
-
|
39
|
-
should "build a checkbox with the proper parameters" do
|
40
|
-
expected_options = base_options.merge(:checked => true)
|
41
|
-
@template.expects(:check_box).with(@object_name, @property, expected_options, '1', '0')
|
42
|
-
@proxy.check_box(@property)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "when called with checked false for a truth value" do
|
47
|
-
setup do
|
48
|
-
settings = stub(@property => '0', "#{@property}?".to_sym => false)
|
49
|
-
@object.stubs(@property_set).returns(settings)
|
50
|
-
end
|
51
|
-
|
52
|
-
should "build a checkbox with the proper parameters" do
|
53
|
-
expected_options = base_options.merge(:checked => false)
|
54
|
-
@template.expects(:check_box).with(@object_name, @property, expected_options, '1', '0')
|
55
|
-
@proxy.check_box(@property)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "#hidden_field" do
|
61
|
-
context "when the persisted value is not a boolean" do
|
62
|
-
setup do
|
63
|
-
settings = stub(@property => 'persisted value')
|
64
|
-
@object.stubs(@property_set).returns(settings)
|
65
|
-
end
|
66
|
-
|
67
|
-
should "build a hidden field with the persisted value" do
|
68
|
-
expected_options = base_options.merge(:value => 'persisted value')
|
69
|
-
@template.expects(:hidden_field).with(@object_name, @property, expected_options)
|
70
|
-
@proxy.hidden_field(@property)
|
71
|
-
end
|
72
|
-
|
73
|
-
context "and a value is provided" do
|
74
|
-
should "build a hidden field with the provided value" do
|
75
|
-
expected_options = base_options.merge(:value => 'provided value')
|
76
|
-
@template.expects(:hidden_field).with(@object_name, @property, expected_options)
|
77
|
-
@proxy.hidden_field(@property, {:value => 'provided value'})
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context "when the persisted value is a boolean" do
|
83
|
-
should "build a hidden field with cast boolean value if it is a boolean true" do
|
84
|
-
settings = stub(@property => true)
|
85
|
-
@object.stubs(@property_set).returns(settings)
|
86
|
-
|
87
|
-
expected_options = base_options.merge(:value => '1')
|
88
|
-
@template.expects(:hidden_field).with(@object_name, @property, expected_options)
|
89
|
-
@proxy.hidden_field(@property)
|
90
|
-
end
|
91
|
-
|
92
|
-
should "build a hidden field with cast boolean value if it is a boolean false" do
|
93
|
-
settings = stub(@property => false)
|
94
|
-
@object.stubs(@property_set).returns(settings)
|
95
|
-
|
96
|
-
expected_options = base_options.merge(:value => '0')
|
97
|
-
@template.expects(:hidden_field).with(@object_name, @property, expected_options)
|
98
|
-
@proxy.hidden_field(@property)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context "#text_field" do
|
104
|
-
context "when called with a provided value" do
|
105
|
-
setup do
|
106
|
-
settings = stub(@property => 'persisted value')
|
107
|
-
@object.stubs(@property_set).returns(settings)
|
108
|
-
end
|
109
|
-
|
110
|
-
should "build a text field with the provided value" do
|
111
|
-
expected_options = base_options.merge(:value => 'provided value')
|
112
|
-
@template.expects(:text_field).with(@object_name, @property, expected_options)
|
113
|
-
@proxy.text_field(@property, {:value => 'provided value'})
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
context "#radio_button" do
|
119
|
-
setup do
|
120
|
-
settings = stub(@property => 'hello')
|
121
|
-
@object.stubs(@property_set).returns(settings)
|
122
|
-
|
123
|
-
@expected_options = base_options.merge(
|
124
|
-
:id => "#{@object_name}_#{@property_set}_#{@property}_hello",
|
125
|
-
:checked => false
|
126
|
-
)
|
127
|
-
end
|
128
|
-
|
129
|
-
should "generate a unique id when one is not provided" do
|
130
|
-
@expected_options.merge!(
|
131
|
-
:id => "#{@object_name}_#{@property_set}_#{@property}_pancake"
|
132
|
-
)
|
133
|
-
@template.expects(:radio_button).with(@object_name, @property, 'pancake', @expected_options)
|
134
|
-
@proxy.radio_button(@property, 'pancake')
|
135
|
-
end
|
136
|
-
|
137
|
-
context "when called with checked true for a truth value" do
|
138
|
-
|
139
|
-
should "call with checked true for a truth value" do
|
140
|
-
@expected_options.merge!(:checked => true)
|
141
|
-
@template.expects(:radio_button).with(@object_name, @property, 'hello', @expected_options)
|
142
|
-
@proxy.radio_button(@property, 'hello')
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context "when called with a value of a different type" do
|
147
|
-
setup do
|
148
|
-
settings = stub(@property => '1')
|
149
|
-
@object.stubs(@property_set).returns(settings)
|
150
|
-
end
|
151
|
-
|
152
|
-
should "call with checked false" do
|
153
|
-
@expected_options.merge!(
|
154
|
-
:id => "#{@object_name}_#{@property_set}_#{@property}_1"
|
155
|
-
)
|
156
|
-
@template.expects(:radio_button).with(@object_name, @property, 1, @expected_options)
|
157
|
-
@proxy.radio_button(@property, 1)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
context "#select" do
|
163
|
-
setup do
|
164
|
-
settings = stub(:count => '2')
|
165
|
-
@object.stubs(@property_set).returns(settings)
|
166
|
-
end
|
167
|
-
|
168
|
-
should "render a <select> with <option>s" do
|
169
|
-
select_options = { :selected => "2" }
|
170
|
-
select_choices = [["One", 1], ["Two", 2], ["Three", 3]]
|
171
|
-
|
172
|
-
@template.expects(:select).with("object_name[settings]", :count, select_choices, select_options, {})
|
173
|
-
@proxy.select(:count, select_choices)
|
174
|
-
end
|
175
|
-
|
176
|
-
should "merge :html_options" do
|
177
|
-
select_options = { :selected => "2" }
|
178
|
-
select_choices = [["One", 1], ["Two", 2], ["Three", 3]]
|
179
|
-
html_options = { :id => "foo", :name => "bar", :disabled => true }
|
180
|
-
|
181
|
-
@template.expects(:select).with("object_name[settings]", :count, select_choices, select_options, html_options)
|
182
|
-
@proxy.select(:count, select_choices, select_options, html_options)
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
private
|
188
|
-
|
189
|
-
def base_options
|
190
|
-
{
|
191
|
-
:name => "#{@object_name}[#{@property_set}][#{@property}]",
|
192
|
-
:id => "#{@object_name}_#{@property_set}_#{@property}",
|
193
|
-
:object => @object
|
194
|
-
}
|
195
|
-
end
|
196
|
-
|
197
|
-
end
|
198
|
-
|