
step "the supplier visits the tables page" do
  visit "/supplier#/tables"
end

step "the supplier clicks on the new table button" do
  find('.new-table-button').click
end

step "the supplier fills in the new table form selecting the first section" do
  within '.modal' do
    js_set_field '.number input', 7
    find('.section select').find(%|option[value="#{@sections.first.id}"]|).select_option
  end
end

step "the supplier submits the table form" do
  #find('.save-table-button').click
  within '.modal' do
    find('.modal-confirm').click
  end
end

step "the new supplier table with proper properties should have been created" do
  @table = Table.find_by_number 7
  @table.section_id.should == @sections.first.id
end

step "the supplier clicks on the edit table button" do
  @table.reload
  find('.table-edit').click
end

step "the supplier changes the table number to :number and section to the last section" do |number|
  within '.modal' do
    js_set_field '.number input', number
    find('.section select').find(%|option[value="#{@sections.last.id}"]|).select_option
  end
end

step "the supplier table should have number :number and be linked to the last section" do |number|
  @table.reload
  expect( @table.number ).to eq number.to_i
  expect( @table.section_id ).to eq @sections.last.id
end
