Skip to content

Commit 736eeb6

Browse files
committed
Rename step#update! method
Bang methods usually indicate that they perform some sort of "dangerous" operation, such as modifying the object in place or raising an exception on failure. In this case, the `update!` method is updating attributes on a question object, but not saving it anywhere so the bang seems unnecessary and misleading. The method name `update` didn't make much sense either, as "update" would indicate that we are saving the object. Rename to `assign_question_attributes` to better reflect the behaviour.
1 parent a4597de commit 736eeb6

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

app/controllers/forms/page_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def show
1717

1818
def save
1919
page_params = params.fetch(:question, {}).permit(*@step.params)
20-
@step.update!(page_params)
20+
@step.assign_question_attributes(page_params)
2121

2222
current_context.clear_submission_details if is_first_page?
2323

app/controllers/forms/selection_none_of_the_above_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def show
1111
def save
1212
page_params = params.fetch(:question, {}).permit(*@step.params)
1313
@step.question.with_none_of_the_above_selected
14-
@step.update!(page_params)
14+
@step.assign_question_attributes(page_params)
1515

1616
if current_context.save_step(@step)
1717
unless mode.preview?

app/models/step.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def load_from_store(answer_store)
4848
self
4949
end
5050

51-
def update!(params)
51+
def assign_question_attributes(params)
5252
question.assign_attributes(params)
5353
end
5454

spec/lib/flow/context_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
current_step = @context.find_or_create(@context.next_page_slug)
4343

4444
input[:answers].each do |answer|
45-
current_step.update!(answer)
45+
current_step.assign_question_attributes(answer)
4646
@context.save_step(current_step)
4747
next_page_slug = current_step.next_page_slug
4848
break if next_page_slug.nil?
@@ -84,7 +84,7 @@
8484
# submit an answer to our page
8585
context1 = described_class.new(form:, store:)
8686
current_step = context1.find_or_create("1")
87-
current_step.update!({ text: "This is a text answer" })
87+
current_step.assign_question_attributes({ text: "This is a text answer" })
8888
context1.save_step(current_step)
8989

9090
# change the page's answer_type to another value

spec/models/step_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@
9898
end
9999
end
100100

101-
describe "#update!" do
101+
describe "#assign_question_attributes" do
102102
it "assigns attributes" do
103103
params = { name: "New Name" }
104104
expect(question).to receive(:assign_attributes).with(params)
105-
step.update!(params)
105+
step.assign_question_attributes(params)
106106
end
107107
end
108108

0 commit comments

Comments
 (0)