acts-as-optionable 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.3
|
@@ -17,7 +17,7 @@ module ActiveRecord
|
|
17
17
|
module IntanceMethods
|
18
18
|
# Store an option persistently and override default option
|
19
19
|
def set_option(name, value, opts = {})
|
20
|
-
option = get_stored_option(name) || options.build(:name => name.to_s, :value => value, :kind => opts[:kind], :display_name => opts[:display_name], :category => opts[:category])
|
20
|
+
option = get_stored_option(name) || options.build(:name => name.to_s, :value => value, :kind => opts[:kind], :display_name => opts[:display_name], :category => opts[:category], :position => opts[:position])
|
21
21
|
return if !opts[:force_set] && new_option_matches_current?(option, value)
|
22
22
|
option.value = value
|
23
23
|
ret = option.save!
|
@@ -6,7 +6,7 @@ module ActiveRecord
|
|
6
6
|
# Setup a default value at the class level.
|
7
7
|
def specify_option(option_name, opts = {})
|
8
8
|
name = option_name.to_s
|
9
|
-
optionable_specified_options[name] = Option.new_readonly(:name => name, :default => opts[:default], :kind => opts[:kind], :display_name => opts[:display_name], :category => opts[:category])
|
9
|
+
optionable_specified_options[name] = Option.new_readonly(:name => name, :default => opts[:default], :kind => opts[:kind], :display_name => opts[:display_name], :category => opts[:category], :position => opts[:position])
|
10
10
|
end
|
11
11
|
|
12
12
|
# Returns a hash of options specified at the class level
|
@@ -40,7 +40,7 @@ module ActiveRecord
|
|
40
40
|
@instance_specified_options = {}
|
41
41
|
opts.each do |option_name, attributes|
|
42
42
|
attributes.symbolize_keys!
|
43
|
-
@instance_specified_options[option_name.to_s] = Option.new_readonly(:name => option_name.to_s, :default => attributes[:default], :kind => attributes[:kind], :display_name => attributes[:display_name], :category => attributes[:category])
|
43
|
+
@instance_specified_options[option_name.to_s] = Option.new_readonly(:name => option_name.to_s, :default => attributes[:default], :kind => attributes[:kind], :display_name => attributes[:display_name], :category => attributes[:category], :position => attributes[:position])
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -9,7 +9,7 @@ class SpecifiedMixin < Mixin
|
|
9
9
|
acts_as_optionable
|
10
10
|
|
11
11
|
specify_option :foo, :default => "FOOFOO"
|
12
|
-
specify_option :bar, :default => "BARBAR", :kind => "example", :display_name => "Bar Bar", :category => "tabs"
|
12
|
+
specify_option :bar, :default => "BARBAR", :kind => "example", :display_name => "Bar Bar", :category => "tabs", :position => 9
|
13
13
|
end
|
14
14
|
|
15
15
|
class NoSpecifiedMixin < Mixin
|
@@ -32,6 +32,7 @@ def setup_db
|
|
32
32
|
t.string :value
|
33
33
|
t.string :kind
|
34
34
|
t.string :category
|
35
|
+
t.integer :position, :default => 0
|
35
36
|
t.references :optionable, :polymorphic => true
|
36
37
|
t.timestamps
|
37
38
|
end
|
@@ -89,6 +90,10 @@ describe "ActsAsOptionable" do
|
|
89
90
|
@optionable.get_option(:bar).category.should == "tabs"
|
90
91
|
end
|
91
92
|
|
93
|
+
it "should be able to specify a position" do
|
94
|
+
@optionable.get_option(:bar).position.should == 9
|
95
|
+
end
|
96
|
+
|
92
97
|
it "should not mix specifications across unrelated classes" do
|
93
98
|
class Foobar < Mixin
|
94
99
|
acts_as_optionable
|
@@ -133,6 +138,11 @@ describe "ActsAsOptionable" do
|
|
133
138
|
@optionable.get_option(:category_is_set).category.should == "tabs"
|
134
139
|
end
|
135
140
|
|
141
|
+
it "should have the position if set" do
|
142
|
+
@optionable.instance_specified_options = @options_template.merge(:position_is_set => {:default => "position_is_set", :position => 99 })
|
143
|
+
@optionable.get_option(:position_is_set).position.should == 99
|
144
|
+
end
|
145
|
+
|
136
146
|
it "should have the display name if set" do
|
137
147
|
@optionable.instance_specified_options = @options_template.merge(:display_name_is_set => {:default => "kind_is_set", :kind => "example_kind", :display_name => "Example Name" })
|
138
148
|
@optionable.get_option(:display_name_is_set).display_name.should == "Example Name"
|
@@ -224,6 +234,11 @@ describe "ActsAsOptionable" do
|
|
224
234
|
@optionable.get_option(@key).category.should == "tabs"
|
225
235
|
end
|
226
236
|
|
237
|
+
it "should allow storing the option position" do
|
238
|
+
@optionable.set_option(@key, "foo", :position => 3)
|
239
|
+
@optionable.get_option(@key).position.should == 3
|
240
|
+
end
|
241
|
+
|
227
242
|
it "should not update the option if it already matches current" do
|
228
243
|
@optionable.set_option(@key, "red", "color")
|
229
244
|
timestamp = @optionable.get_option(@key).updated_at.dup
|
@@ -329,7 +344,7 @@ describe "ActsAsOptionable" do
|
|
329
344
|
|
330
345
|
describe "getting options and defaults as a hash" do
|
331
346
|
before(:each) do
|
332
|
-
@optionable.set_option("example_option", "example_value", :kind => "example", :display_name => "Example Name", :category => "tabs")
|
347
|
+
@optionable.set_option("example_option", "example_value", :kind => "example", :display_name => "Example Name", :category => "tabs", :position => 99)
|
333
348
|
@options_and_defaults_hash = @optionable.options_and_defaults_hash
|
334
349
|
end
|
335
350
|
|
@@ -355,6 +370,10 @@ describe "ActsAsOptionable" do
|
|
355
370
|
@options_and_defaults_hash["example_option"]["category"].should == "tabs"
|
356
371
|
end
|
357
372
|
|
373
|
+
it "should include the position" do
|
374
|
+
@options_and_defaults_hash["example_option"]["position"].should == 99
|
375
|
+
end
|
376
|
+
|
358
377
|
it "should include the display name" do
|
359
378
|
@options_and_defaults_hash["example_option"]["display_name"].should == "Example Name"
|
360
379
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 3
|
9
|
+
version: 0.4.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Brendon Murphy
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-17 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|