Browse Source

Fixed creating bike work time entry & added spec

denney-fix-saving-dates
Jason Denney 11 years ago
parent
commit
0605d0f0d9
  1. 5
      app/controllers/api/v1/time_entries_controller.rb
  2. 17
      spec/features/time_entries/new_spec.rb

5
app/controllers/api/v1/time_entries_controller.rb

@ -8,11 +8,12 @@ class Api::V1::TimeEntriesController < Api::V1::BaseController
logger_id: current_user.id }) logger_id: current_user.id })
bike_id = time_entry[:bike_id].to_i bike_id = time_entry[:bike_id].to_i
@time_entry = TimeEntry.new(time_entry.except(:bike_id))
if bike_id > 0 if bike_id > 0
time_entry.copy_to_bike_history(bike_id) @time_entry.copy_to_bike_history(bike_id)
end end
@time_entry = TimeEntry.new(time_entry.except(:bike_id))
if !@time_entry.save if !@time_entry.save
render json: { errors: @time_entry.errors }, status: 422 and return render json: { errors: @time_entry.errors }, status: 422 and return
end end

17
spec/features/time_entries/new_spec.rb

@ -22,6 +22,23 @@ feature "TimeEntries" do
expect(TimeEntry.count).to be > 0 expect(TimeEntry.count).to be > 0
end end
context "A bike exists" do
let!(:bike){ FactoryGirl.create(:bike) }
scenario "User creates a new bike work time entry", js: true do
visit new_time_entry_path
fill_in "date_id", with: "04/27/2014"
fill_in "start_time_id", with: "3:00 PM"
fill_in "end_time_id", with: "3:15 PM"
find('label.btn.btn-default', text: 'Personal').trigger('click')
select bike.to_s, from: "bike_id"
fill_in "description_id", with: "My Description"
click_button "Add Time Entry"
expect(page).to have_text("Task List")
expect(TimeEntry.count).to be > 0
end
end
scenario "User submits a time entry with errors", js: true do scenario "User submits a time entry with errors", js: true do
visit new_time_entry_path visit new_time_entry_path
click_button "Add Time Entry" click_button "Add Time Entry"

Loading…
Cancel
Save