diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index f782c4e..745e5b4 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -22,6 +22,6 @@ class TimeEntry < ActsAsLoggable::Log end def type - log_action.action + log_action.try(:action) end end diff --git a/app/models/user.rb b/app/models/user.rb index d51757b..a455258 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -65,15 +65,14 @@ class User < ActiveRecord::Base end def total_credits_spent - log_action = ::ActsAsLoggable::TransactionAction.find_by_action("TIME") + log_action_id = 1 #TIME transaction_logs. where( "log_action_id = ? AND log_action_type = ?", - log_action.id, log_action.class.to_s). + log_action_id, ::ActsAsLoggable::TransactionAction.to_s). sum{ |r| r.description.to_i }.round(2) end def total_earned_credits - log_action = ::ActsAsLoggable::UserAction.find_by_action("CHECKIN") volunteer_id = 1 staff_id = 3 @@ -98,20 +97,20 @@ class User < ActiveRecord::Base ORDER BY logs.created_at, conversion.created_at DESC", {id: self.id, credit_actions: [volunteer_id, staff_id], - log_action_type: log_action.class.to_s}]). + log_action_type: ::ActsAsLoggable::UserAction.to_s}]). sum{ |l| ((l.end_date - l.start_date)/3600) * l.conversion.to_i}.round(2) end def total_hours - log_action = ::ActsAsLoggable::UserAction.find_by_action("CHECKIN") - logs.where("log_action_id != ? AND log_action_type = ?", log_action.id, log_action.class.to_s).sum { |l| (l.end_date - l.start_date)/3600 }.round(2) + log_action_id = 4 #CHECKIN + logs.where("log_action_id != ? AND log_action_type = ?", log_action_id, ::ActsAsLoggable::UserAction.to_s).sum { |l| (l.end_date - l.start_date)/3600 }.round(2) end def current_month_hours - log_action = ::ActsAsLoggable::UserAction.find_by_action("CHECKIN") + log_action_id = 4 #CHECKIN #TODO need to prevent users from saving logs across months, force to create a new log if crossing month current_month_range = (Time.now.beginning_of_month..Time.now.end_of_month) - logs.where("log_action_id != ? AND log_action_type = ?", log_action.id, log_action.class.to_s) + logs.where("log_action_id != ? AND log_action_type = ?", log_action_id, ::ActsAsLoggable::UserAction.to_s) .where( :start_date => current_month_range) .where( :end_date => current_month_range) .sum { |l| (l.end_date - l.start_date)/3600 } diff --git a/spec/features/time_entries/index_spec.rb b/spec/features/time_entries/index_spec.rb new file mode 100644 index 0000000..6ce04d8 --- /dev/null +++ b/spec/features/time_entries/index_spec.rb @@ -0,0 +1,23 @@ +require "spec_helper" + +feature "TimeEntries" do + let!(:user){ FactoryGirl.create(:user) } + let!(:entry){ FactoryGirl.create(:time_entry, loggable_id: user.id) } + + before(:each) do + visit new_user_session_path + fill_in "user_username", with: user.username + fill_in "user_password", with: user.password + click_button "Sign in" + end + + scenario "User deletes a time entry", js: true do + visit time_entries_path + puts TimeEntry.where(loggable_id: user.id).inspect + save_screenshot("/tmp/testingpoop.png") + find('button.work_entry-delete-btn').trigger('click') + click_button "Delete" + expect(page).to have_text("Your Timesheet") + expect(TimeEntry.count).to eql 0 + end +end