enumerize 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7398da2a4b6b495fe048cf6872660b0c8ac55278197f0f31e04e6de360691152
4
- data.tar.gz: 88d7a066d937fa8654b9878a85d16d2ac4f9048be29e211ba26d828967c60041
3
+ metadata.gz: '09a21a038b965b870133316f6ff3343c673999dc49fc619045695e2b56acd5be'
4
+ data.tar.gz: 031bb09cc643bff2ab3fbc1b9d3786ece309d684841a6199d11082aa14169c56
5
5
  SHA512:
6
- metadata.gz: 14ef4618d73da931a8cfeae83a9d650c9ae98d5bf876bdc72b151e182bbb345c86fe7fe495f8f096f61f170a75b29a12478b7f02081d277cd467c541bf2bf158
7
- data.tar.gz: d8868aa8ac94d9920de256382460f2ea36343a72b89b9aa46ce0369248b940602c27014da4ff7fbee411d43b7eb0ada4442866857ae779414d0fdd0f57902a60
6
+ metadata.gz: 53ebadba90aaf20fd45007f386d2de7a702b3ee1973992675136a41be99fe92889e1c852c409fa0ae8eea1d948b5cfec08163a1b3b0f13fb58de7984992e9a01
7
+ data.tar.gz: f8f90dd597f8ae953f8c162682ee96e24e49b0b4685b21d9003991c9779fb9abe9764b7cf4d5f6afeafce2a0a2f5ed073b3a00251210268cab76db6a45ba9b65
@@ -4,6 +4,12 @@
4
4
 
5
5
  ### bug fix
6
6
 
7
+ ## 2.2.2 (March 6, 2018)
8
+
9
+ ### bug fix
10
+
11
+ * Support non-ActiveModel objects in SimpleForm/Formtastic integration. (by [@nashby](https://github.com/nashby))
12
+
7
13
  ## 2.2.1 (February 15, 2018)
8
14
 
9
15
  ### bug fix
@@ -5,7 +5,8 @@ module Enumerize
5
5
  module FormtasticFormBuilderExtension
6
6
 
7
7
  def input(method, options={})
8
- klass = object && object.to_model.class
8
+ enumerized_object = convert_to_model(object)
9
+ klass = enumerized_object.class
9
10
 
10
11
  if klass.respond_to?(:enumerized_attributes) && (attr = klass.enumerized_attributes[method])
11
12
  options[:collection] ||= attr.options
@@ -17,7 +17,8 @@ module Enumerize
17
17
  private
18
18
 
19
19
  def add_input_options_for_enumerized_attribute(attribute_name, options)
20
- klass = object && object.to_model.class
20
+ enumerized_object = convert_to_model(object)
21
+ klass = enumerized_object.class
21
22
 
22
23
  if klass.respond_to?(:enumerized_attributes) && (attr = klass.enumerized_attributes[attribute_name])
23
24
  options[:collection] ||= attr.options
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Enumerize
4
- VERSION = '2.2.1'
4
+ VERSION = '2.2.2'
5
5
  end
@@ -42,6 +42,12 @@ class FormtasticSpec < MiniTest::Spec
42
42
  end
43
43
  end
44
44
 
45
+ class Registration < Struct.new(:sex)
46
+ extend Enumerize
47
+
48
+ enumerize :sex, in: [:male, :female]
49
+ end
50
+
45
51
  before { $VERBOSE = nil }
46
52
  after { $VERBOSE = true }
47
53
 
@@ -125,6 +131,15 @@ class FormtasticSpec < MiniTest::Spec
125
131
  assert_select 'input[type=text]'
126
132
  end
127
133
 
134
+ it 'renders select with enumerized values for non-ActiveModel object' do
135
+ concat(semantic_form_for(Registration.new, as: 'registration', url: '/') do |f|
136
+ f.input(:sex)
137
+ end)
138
+
139
+ assert_select 'select option[value=male]'
140
+ assert_select 'select option[value=female]'
141
+ end
142
+
128
143
  it 'does not affect forms without object' do
129
144
  concat(semantic_form_for('') do |f|
130
145
  f.input(:name)
@@ -40,6 +40,12 @@ class SimpleFormSpec < MiniTest::Spec
40
40
  end
41
41
  end
42
42
 
43
+ class Registration < Struct.new(:sex)
44
+ extend Enumerize
45
+
46
+ enumerize :sex, in: [:male, :female]
47
+ end
48
+
43
49
  let(:user) { User.new }
44
50
  let(:post) { Post.new }
45
51
 
@@ -129,6 +135,15 @@ class SimpleFormSpec < MiniTest::Spec
129
135
  assert_select 'input.string'
130
136
  end
131
137
 
138
+ it 'renders select with enumerized values for non-ActiveModel object' do
139
+ concat(simple_form_for(Registration.new, as: 'registration', url: '/') do |f|
140
+ f.input(:sex)
141
+ end)
142
+
143
+ assert_select 'select option[value=male]'
144
+ assert_select 'select option[value=female]'
145
+ end
146
+
132
147
  it 'does not affect forms without object' do
133
148
  concat(simple_form_for('') do |f|
134
149
  f.input(:name)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumerize
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Nartimov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-15 00:00:00.000000000 Z
11
+ date: 2018-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport