property_sets 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.3
1
+ 0.5.4
@@ -36,25 +36,25 @@ module ActionView
36
36
  template.hidden_field(object_name, property, prepare_id_name(property, options))
37
37
  end
38
38
 
39
- def select(property, choices, options = {})
39
+ def select(property, choices, options = {}, html_options = {})
40
40
  options = prepare_id_name(property, options)
41
41
  current_value = options[:object].send(property_set).send(property)
42
- template.select("#{object_name}[#{property_set}]", property, choices, :selected => current_value)
42
+ template.select("#{object_name}[#{property_set}]", property, choices, { :selected => current_value }, html_options )
43
43
  end
44
44
 
45
45
  def prepare_id_name(property, options)
46
46
  throw "Invalid options type #{options.inspect}" unless options.is_a?(Hash)
47
47
 
48
- instance = template.instance_variable_get("@#{object_name}")
48
+ options.clone.tap do |prepared_options|
49
+ instance = template.instance_variable_get("@#{object_name}")
49
50
 
50
- throw "No @#{object_name} in scope" if instance.nil?
51
- throw "The property_set_check_box only works on models with property set #{property_set}" unless instance.respond_to?(property_set)
51
+ throw "No @#{object_name} in scope" if instance.nil?
52
+ throw "The property_set_check_box only works on models with property set #{property_set}" unless instance.respond_to?(property_set)
52
53
 
53
- options[:id] ||= "#{object_name}_#{property_set}_#{property}"
54
- options[:name] = "#{object_name}[#{property_set}][#{property}]"
55
- options[:object] = instance
56
-
57
- options
54
+ prepared_options[:id] ||= "#{object_name}_#{property_set}_#{property}"
55
+ prepared_options[:name] = "#{object_name}[#{property_set}][#{property}]"
56
+ prepared_options[:object] = instance
57
+ end
58
58
  end
59
59
 
60
60
  def prepare_options(property, options, &block)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{property_sets}
8
- s.version = "0.5.3"
8
+ s.version = "0.5.4"
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-08-16}
12
+ s.date = %q{2011-09-22}
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 = [
@@ -43,6 +43,12 @@ Gem::Specification.new do |s|
43
43
  s.require_paths = ["lib"]
44
44
  s.rubygems_version = %q{1.6.2}
45
45
  s.summary = %q{Property sets for ActiveRecord}
46
+ s.test_files = [
47
+ "test/helper.rb",
48
+ "test/schema.rb",
49
+ "test/test_property_sets.rb",
50
+ "test/test_view_extensions.rb"
51
+ ]
46
52
 
47
53
  if s.respond_to? :specification_version then
48
54
  s.specification_version = 3
data/test/helper.rb CHANGED
@@ -54,4 +54,11 @@ class Account < ActiveRecord::Base
54
54
 
55
55
  validates_format_of :value, :with => /\d+/, :message => "BEEP", :if => lambda { |r| r.name.to_sym == :validated }
56
56
  end
57
+
58
+ property_set :typed_data do
59
+ property :string_prop, :type => :string
60
+ property :datetime_prop, :type => :datetime
61
+ property :float_prop, :type => :float
62
+ property :int_prop, :type => :integer
63
+ end
57
64
  end
@@ -110,22 +110,34 @@ class TestViewExtensions < ActiveSupport::TestCase
110
110
  end
111
111
 
112
112
  context "select" do
113
- should "render a <select> with <option>s" do
113
+ setup do
114
114
  settings = stub(:count => "2")
115
115
  object = stub()
116
- object.expects(@association).returns(settings)
116
+ object.stubs(@association).returns(settings)
117
117
 
118
- template = stub()
119
- template.expects(:instance_variable_get).with("@object_name").returns(object)
118
+ @template = stub()
119
+ @template.expects(:instance_variable_get).with("@object_name").returns(object)
120
+ end
121
+
122
+ should "render a <select> with <option>s" do
120
123
 
121
124
  select_options = { :selected => "2" }
122
125
  select_choices = [["One", 1], ["Two", 2], ["Three", 3]]
123
- html_options = { :id => "foo", :name => "bar" }
124
- template.expects(:select).with("object_name[settings]", :count, select_choices, select_options)
125
126
 
126
- @proxy.stubs(:template).returns(template)
127
+ @template.expects(:select).with("object_name[settings]", :count, select_choices, select_options, {})
128
+ @proxy.stubs(:template).returns(@template)
127
129
  @proxy.select(:count, select_choices)
128
130
  end
131
+
132
+ should "merge :html_options" do
133
+ select_options = { :selected => "2" }
134
+ select_choices = [["One", 1], ["Two", 2], ["Three", 3]]
135
+ html_options = { :id => "foo", :name => "bar", :disabled => true }
136
+
137
+ @template.expects(:select).with("object_name[settings]", :count, select_choices, select_options, html_options)
138
+ @proxy.stubs(:template).returns(@template)
139
+ @proxy.select(:count, select_choices, select_options, html_options)
140
+ end
129
141
  end
130
142
  end
131
143
  end
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: 13
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 3
10
- version: 0.5.3
9
+ - 4
10
+ version: 0.5.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Morten Primdahl
@@ -15,12 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-16 00:00:00 -07:00
18
+ date: 2011-09-22 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- type: :runtime
23
- requirement: &id001 !ruby/object:Gem::Requirement
22
+ name: activesupport
23
+ prerelease: false
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
25
  none: false
25
26
  requirements:
26
27
  - - ~>
@@ -31,12 +32,12 @@ dependencies:
31
32
  - 3
32
33
  - 10
33
34
  version: 2.3.10
34
- name: activesupport
35
- version_requirements: *id001
36
- prerelease: false
37
- - !ruby/object:Gem::Dependency
38
35
  type: :runtime
39
- requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirement: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: activerecord
39
+ prerelease: false
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
41
  none: false
41
42
  requirements:
42
43
  - - ~>
@@ -47,12 +48,12 @@ dependencies:
47
48
  - 3
48
49
  - 10
49
50
  version: 2.3.10
50
- name: activerecord
51
- version_requirements: *id002
52
- prerelease: false
53
- - !ruby/object:Gem::Dependency
54
51
  type: :runtime
55
- requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirement: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: actionpack
55
+ prerelease: false
56
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
57
  none: false
57
58
  requirements:
58
59
  - - ~>
@@ -63,12 +64,12 @@ dependencies:
63
64
  - 3
64
65
  - 10
65
66
  version: 2.3.10
66
- name: actionpack
67
- version_requirements: *id003
68
- prerelease: false
67
+ type: :runtime
68
+ requirement: *id003
69
69
  - !ruby/object:Gem::Dependency
70
- type: :development
71
- requirement: &id004 !ruby/object:Gem::Requirement
70
+ name: shoulda
71
+ prerelease: false
72
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
73
  none: false
73
74
  requirements:
74
75
  - - ">="
@@ -77,12 +78,12 @@ dependencies:
77
78
  segments:
78
79
  - 0
79
80
  version: "0"
80
- name: shoulda
81
- version_requirements: *id004
82
- prerelease: false
83
- - !ruby/object:Gem::Dependency
84
81
  type: :development
85
- requirement: &id005 !ruby/object:Gem::Requirement
82
+ requirement: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ prerelease: false
86
+ version_requirements: &id005 !ruby/object:Gem::Requirement
86
87
  none: false
87
88
  requirements:
88
89
  - - ~>
@@ -93,12 +94,12 @@ dependencies:
93
94
  - 0
94
95
  - 0
95
96
  version: 1.0.0
96
- name: bundler
97
- version_requirements: *id005
98
- prerelease: false
99
- - !ruby/object:Gem::Dependency
100
97
  type: :development
101
- requirement: &id006 !ruby/object:Gem::Requirement
98
+ requirement: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ name: jeweler
101
+ prerelease: false
102
+ version_requirements: &id006 !ruby/object:Gem::Requirement
102
103
  none: false
103
104
  requirements:
104
105
  - - ~>
@@ -109,12 +110,12 @@ dependencies:
109
110
  - 5
110
111
  - 1
111
112
  version: 1.5.1
112
- name: jeweler
113
- version_requirements: *id006
114
- prerelease: false
115
- - !ruby/object:Gem::Dependency
116
113
  type: :development
117
- requirement: &id007 !ruby/object:Gem::Requirement
114
+ requirement: *id006
115
+ - !ruby/object:Gem::Dependency
116
+ name: ruby-debug
117
+ prerelease: false
118
+ version_requirements: &id007 !ruby/object:Gem::Requirement
118
119
  none: false
119
120
  requirements:
120
121
  - - ">="
@@ -123,12 +124,12 @@ dependencies:
123
124
  segments:
124
125
  - 0
125
126
  version: "0"
126
- name: ruby-debug
127
- version_requirements: *id007
128
- prerelease: false
129
- - !ruby/object:Gem::Dependency
130
127
  type: :development
131
- requirement: &id008 !ruby/object:Gem::Requirement
128
+ requirement: *id007
129
+ - !ruby/object:Gem::Dependency
130
+ name: thoughtbot-shoulda
131
+ prerelease: false
132
+ version_requirements: &id008 !ruby/object:Gem::Requirement
132
133
  none: false
133
134
  requirements:
134
135
  - - ">="
@@ -137,9 +138,8 @@ dependencies:
137
138
  segments:
138
139
  - 0
139
140
  version: "0"
140
- name: thoughtbot-shoulda
141
- version_requirements: *id008
142
- prerelease: false
141
+ type: :development
142
+ requirement: *id008
143
143
  description: This gem is an ActiveRecord extension which provides a convenient interface for managing per row properties
144
144
  email: morten@zendesk.com
145
145
  executables: []
@@ -205,5 +205,8 @@ rubygems_version: 1.6.2
205
205
  signing_key:
206
206
  specification_version: 3
207
207
  summary: Property sets for ActiveRecord
208
- test_files: []
209
-
208
+ test_files:
209
+ - test/helper.rb
210
+ - test/schema.rb
211
+ - test/test_property_sets.rb
212
+ - test/test_view_extensions.rb