diff --git a/app/controllers/api/v1/time_entries_controller.rb b/app/controllers/api/v1/time_entries_controller.rb index eac33cd..e1b8768 100644 --- a/app/controllers/api/v1/time_entries_controller.rb +++ b/app/controllers/api/v1/time_entries_controller.rb @@ -8,11 +8,12 @@ class Api::V1::TimeEntriesController < Api::V1::BaseController logger_id: current_user.id }) bike_id = time_entry[:bike_id].to_i + @time_entry = TimeEntry.new(time_entry.except(:bike_id)) + if bike_id > 0 - time_entry.copy_to_bike_history(bike_id) + @time_entry.copy_to_bike_history(bike_id) end - @time_entry = TimeEntry.new(time_entry.except(:bike_id)) if !@time_entry.save render json: { errors: @time_entry.errors }, status: 422 and return end diff --git a/spec/features/time_entries/new_spec.rb b/spec/features/time_entries/new_spec.rb index 3138998..eac3280 100644 --- a/spec/features/time_entries/new_spec.rb +++ b/spec/features/time_entries/new_spec.rb @@ -22,6 +22,23 @@ feature "TimeEntries" do expect(TimeEntry.count).to be > 0 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 visit new_time_entry_path click_button "Add Time Entry"