Rails 4 / RSpec - Testing time values persisted to MYSQL database in controller specs -
i'm writing pretty standard rspec controller tests rails app. 1 issue i'm running testing time values have been persisted in update action.
in controller have:
def update if @derp.update_attributes(derp_params) redirect_to @derp, flash: {success: "updated derp successfully."} else render :edit end end
@derp has time attribute of type time. can test of other attributes in update action follows:
describe "patch #update" before @attr = { attribute_1: 5, attribute_2: 6, attribute_3: 7, time: time.zone.now } end end
the error i'm getting is:
1) derpscontroller logged in patch #update updates derps's attributes failure/error: expect(derp.time).to eq(@attr[:time]) expected: 2015-08-24 18:30:32.096943000 -0400 got: 2000-01-01 18:30:32.000000000 +0000 (compared using ==) diff: @@ -1,2 +1,2 @@ -2015-08-24 18:30:32 -0400 +2000-01-01 18:30:32 utc
i've tried using timecop , comparing to_s or to_i...but every attribute of data type time off far year goes. i've seen couple posts saying how can expect within 1 second , how deal that, looks year off?
this can't difficult - want test controller can take time sent , save database.
what missing here?
edit: no here after couple of days. let me try re-iterate what's happening - date being stripped because mysql type time. notice 2000-01-01...
let(:time) {'mon, 24 aug 2015 23:19:09'} describe "patch #update" before @attr = { attribute_1: 5, attribute_2: 6, attribute_3: 7, time: time.in_time_zone('eastern time (us & canada)').to_datetime } end end
rather saving time.zone.now
in record, define time
variable , update record time know time should saved in database. then, expect time when compare.
Comments
Post a Comment