selections 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,20 +1,25 @@
1
- ## 0.0.1
1
+ ## 0.1.7
2
2
 
3
- * Initial release
3
+ * https://github.com/nigelr/selections/issues/5 - issue with forgetting selected item when page was invalid
4
4
 
5
- ## 0.1.1
5
+ ## 0.1.6
6
6
 
7
- * Clean up of specs and readme
7
+ * Fixed issue with options and html_options order
8
+
9
+ ## 0.1.3
10
+
11
+ * Fixing issue with dependencies on Rubygems
8
12
 
9
13
  ## 0.1.2
10
14
 
11
15
  * Fixing issues with readme
12
16
 
13
- ## 0.1.3
17
+ ## 0.1.1
14
18
 
15
- * Fixing issue with dependencies on Rubygems
19
+ * Clean up of specs and readme
16
20
 
17
- ## 0.1.6
21
+ ## 0.0.1
22
+
23
+ * Initial release
18
24
 
19
- * Fixed issue with options and html_options order
20
25
 
@@ -64,8 +64,8 @@ module Selections
64
64
  end
65
65
 
66
66
  def selected_item
67
- if object.new_record?
68
- default_item
67
+ if object.new_record? && object.send(field_id).blank?
68
+ default_item
69
69
  else
70
70
  object.send(field_id).to_s
71
71
  end
@@ -1,3 +1,3 @@
1
1
  module Selections
2
- VERSION = "0.1.6"
2
+ VERSION = '0.1.7'
3
3
  end
@@ -13,7 +13,7 @@ def new_form args = {}
13
13
  end
14
14
 
15
15
  def common_form args = {}
16
- args[:form] ||= form
16
+ args[:form] ||= form
17
17
  args[:field] ||= :priority
18
18
  args[:html_options] ||= {}
19
19
  args[:options] ||= {}
@@ -45,13 +45,13 @@ describe SelectionTag do
45
45
  before { model_parent }
46
46
  it("should find more explicit route of model parent") { expect(edit_form.system_code).to eq(model_parent) }
47
47
  it "should use priority system_code when model is not ticket" do
48
- expect(edit_form(form: ActionView::Helpers::FormBuilder.new(:user, :user, ActionView::Base.new, {}, Proc.new {}) ).system_code).to eq(parent)
48
+ expect(edit_form(form: ActionView::Helpers::FormBuilder.new(:user, :user, ActionView::Base.new, {}, Proc.new {})).system_code).to eq(parent)
49
49
  end
50
50
  end
51
51
  end
52
52
 
53
53
  context "system_code override" do
54
- it "meme" do
54
+ it 'passes through system code' do
55
55
  hello = Selection.create(name: "hello")
56
56
  parent
57
57
  expect(new_form(options: {system_code: :hello} ).system_code).to eq hello
@@ -174,21 +174,54 @@ describe SelectionTag do
174
174
  before { all_selections }
175
175
 
176
176
  context "when default not set" do
177
- it("when new form") { expect(new_form.selected_item).to eq("") }
178
- it "when edit form with ticket.priority_id set" do
179
- ticket.update_attribute(:priority_id, selection_3.id)
180
- expect(edit_form.selected_item).to eq(selection_3.id.to_s)
177
+ context "when new form" do
178
+ it 'has no value' do
179
+ expect(new_form.selected_item).to eq("")
180
+ end
181
+ it 'priority value is already set (simulating a failed validation)' do
182
+ expect(new_form(object: Ticket.new(priority_id: selection_3.id)).selected_item).to eq(selection_3.id.to_s)
183
+ end
184
+ end
185
+ context "when edit form" do
186
+ context "ticket.priority_id set" do
187
+ before { ticket.update_attribute(:priority_id, selection_3.id) }
188
+
189
+ it { expect(edit_form.selected_item).to eq(selection_3.id.to_s) }
190
+ it 'priority value is changed (simulating a failed validation)' do
191
+ expect(edit_form(object: ticket.assign_attributes(priority_id: selection_2.id)).selected_item).to eq(selection_2.id.to_s)
192
+ end
193
+ end
194
+ context 'no ticket.priority_id set' do
195
+ it { expect(edit_form.selected_item).to eq("") }
196
+ it 'priority value is changed (simulating a failed validation)' do
197
+ expect(edit_form(object: ticket.assign_attributes(priority_id: selection_2.id)).selected_item).to eq(selection_2.id.to_s)
198
+ end
199
+ end
181
200
  end
182
- it("when edit form with no ticket.priority_id set") { expect(edit_form.selected_item).to eq("") }
183
201
  end
184
202
  context "when default is set" do
185
203
  before { selection_2.update_attribute(:is_default, true) }
186
- it("when new form") { expect(new_form.selected_item).to eq(selection_2.id.to_s) }
187
- it "when edit form with ticket.priority_id set" do
188
- ticket.update_attribute(:priority_id, selection_3.id)
189
- expect(edit_form.selected_item).to eq(selection_3.id.to_s)
204
+
205
+ context 'new form' do
206
+ it { expect(new_form.selected_item).to eq(selection_2.id.to_s) }
207
+ it 'priority value is already set (simulating a failed validation)' do
208
+ expect(new_form(object: Ticket.new(priority_id: selection_3.id)).selected_item).to eq(selection_3.id.to_s)
209
+ end
210
+ end
211
+
212
+ context 'edit form' do
213
+ it('has no ticket.priority_id set') { expect(edit_form.selected_item).to eq("") }
214
+ context 'has ticket.priority_id set' do
215
+ before { ticket.update_attribute(:priority_id, selection_3.id) }
216
+
217
+ it 'should not change' do
218
+ expect(edit_form.selected_item).to eq(selection_3.id.to_s)
219
+ end
220
+ it 'priority value is changed (simulating a failed validation)' do
221
+ expect(edit_form(object: ticket.assign_attributes(priority_id: selection_2.id)).selected_item).to eq(selection_2.id.to_s)
222
+ end
223
+ end
190
224
  end
191
- it("when edit form with no ticket.priority_id set") { expect(edit_form.selected_item).to eq("") }
192
225
  end
193
226
  end
194
227
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selections
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-11 00:00:00.000000000 Z
12
+ date: 2013-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord