Extract component to render the date of birth
We reduce code duplication thanks to that, and make it easier to change this field. Note that there was one place where the "16.years" value was hardcoded. We're moving the test for this case to the component and changing it so the test doesn't use the default age. We're also removing the redundant helper method that had the same code as a method in the User class which is called everywhere else.
This commit is contained in:
26
spec/components/shared/date_of_birth_field_component_spec.rb
Normal file
26
spec/components/shared/date_of_birth_field_component_spec.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Shared::DateOfBirthFieldComponent do
|
||||
before do
|
||||
dummy_model = Class.new do
|
||||
include ActiveModel::Model
|
||||
attr_accessor :date_of_birth
|
||||
end
|
||||
|
||||
stub_const("DummyModel", dummy_model)
|
||||
end
|
||||
|
||||
let(:form) { ConsulFormBuilder.new(:dummy, DummyModel.new, ApplicationController.new.view_context, {}) }
|
||||
let(:component) { Shared::DateOfBirthFieldComponent.new(form) }
|
||||
|
||||
it "uses the minimum required age as the latest date by default" do
|
||||
Setting["min_age_to_participate"] = 13
|
||||
|
||||
travel_to "2015-07-15" do
|
||||
render_inline component
|
||||
|
||||
expect(page).to have_select with_options: [2002, 2001, 2000, 1999]
|
||||
expect(page).not_to have_select with_options: [2003]
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user