require 'spec_helper' describe "companies/edit" do context "default selection list" do before do @parent_10 = Factory(:selection, :system_code => "state") @child_11 = Factory(:selection, :parent => @parent_10) @child_12 = Factory(:selection, :parent => @parent_10, :is_default => true) @child_13 = Factory(:selection, :parent => @parent_10) @child_14 = Factory(:selection, :parent => @parent_10) @parent_20 = Factory(:selection, :system_code => "priority") @child_21 = Factory(:selection, :parent => @parent_20, :is_default => true) @child_22 = Factory(:selection, :parent => @parent_21) @company = Factory(:company, :state => @child_14) assign(:company, @company) end it "should display error when field does not match system_code" do assign(:field, :not_match) render assert_select "form", "Invalid system_code" end context "standard" do before(:each) do assign(:field, :state) assign(:options, nil) assign(:html_options, nil) end it "selection with default item" do render assert_select "form[action='#{company_path(@company)}'][method='post']" do assert_select "input[type='hidden'][value='put']" assert_select "select#company_state_id[name='company[state_id]']" do selected_options(@parent_10.children, @child_14, false) end end end it "company with no selection set" do @company.update_attribute(:state, nil) render selected_options(@parent_10.children, nil, true) end it "selection with archived item" do @child_13.update_attribute(:archived, true) render selected_options(@parent_10.children-[@child_13], @child_14, false) end it "company with state set that is archived selection" do @child_14.update_attribute(:archived, true) render selected_options(@parent_10.children, @child_14, false) end it "should have blank selection when :include_blank is true" do assign(:options, {:include_blank => true}) render selected_options(@parent_10.children, @child_14, true) end it "should not have blank when non set and :include_blank is false" do assign(:options, {:include_blank => false}) @company.update_attribute(:state, nil) render selected_options(@parent_10.children, nil, false) end it "it should use fieldname which does not match a system_code" do assign(:options, {:system_code => "state"}) assign(:field, :genre) @company.update_attribute(:genre_id, @child_14.id) render selected_options(@parent_10.children, @child_14, false) end end end end