diff --git a/app/cells/state_list_cell.rb b/app/cells/state_list_cell.rb index 6aafd4a..1753c25 100644 --- a/app/cells/state_list_cell.rb +++ b/app/cells/state_list_cell.rb @@ -1,14 +1,14 @@ class StateListCell < Cell::ViewModel include ERB::Util - def initialize(states, options = {}) - @states = states - end - private + def states + model + end + def state_names_and_abbrs - @states.map.with_index(1) {|state, index| name_and_abbr state, index } + states.map.with_index(1) {|state, index| name_and_abbr state, index } end def name_and_abbr(state, index) diff --git a/app/cells/state_selector_cell.rb b/app/cells/state_selector_cell.rb index e41bceb..0c3d56e 100644 --- a/app/cells/state_selector_cell.rb +++ b/app/cells/state_selector_cell.rb @@ -2,19 +2,16 @@ class StateSelectorCell < Cell::ViewModel include ActionView::Helpers::FormHelper include ActionView::Helpers::FormOptionsHelper - attr_reader :states, :url + private - def initialize(states, options) - super - @states = states - @url = options[:url] + def states + model end - def show - render + def url + @url ||= options[:url] end - private def locale_state_options @locale_state_options ||= states_for_menu.sort_by {|state| _(state.name)}.map {|state| [_(state.name), state.abbr]} diff --git a/spec/cells/state_selector_cell_spec.rb b/spec/cells/state_selector_cell_spec.rb index e8406e4..6ce1c74 100644 --- a/spec/cells/state_selector_cell_spec.rb +++ b/spec/cells/state_selector_cell_spec.rb @@ -17,22 +17,6 @@ end end - context '#states' do - let(:states) { State.all.sample rand(2..5) } - - it 'returns the given states' do - expect(subject.states).to be == states - end - end - - context '#url' do - let(:url) { File.join *Faker::Lorem.words(rand 2..5) } - - it 'returns the given URL' do - expect(subject.url).to be == url - end - end - context '#show' do controller Class.new(ApplicationController) # see https://github.com/trailblazer/rspec-cells#url-helpers @@ -45,7 +29,7 @@ expect(subject).to have_selector "form[action='#{url}']" end - it 'renders a multi-select with all the states as options, sorted by nam,e' do + it 'renders a multi-select with all the states as options, sorted by name' do subject.find menu do |menu| selector = './/' + State.all.sort_by(&:name).map {|state| "option[@value='#{state.abbr}'][text()='#{state.name}']"}.join('/following-sibling::') expect(menu).to have_xpath selector