Note that there are some explanatory texts on larger screens.

plurals
  1. POsqlite3/data_mapper always saves time as 00:00:00 when using rspec only
    primarykey
    data
    text
    <p>I have a peculiar issue involving saving time using data_mapper and sqlite3 and rspec</p> <p>if I run the spec below I get this failure report</p> <pre><code> # expected: 2013-01-04 07:30:00 +1100 # got: 2013-01-04 00:00:00 +1100 </code></pre> <p>if I try to save the file manually in irb I get</p> <pre><code> # irb(main):003:0&gt; Sleep.create(:id =&gt; 1, :wake_time =&gt; Time.new(2013, 01, 04, 07, 30, 00)) # =&gt; #&lt;Sleep @id=1 @wake_time=2013-01-04 07:30:00 +1100&gt; </code></pre> <p>In summary, if I run the rspec test which takes a string, breaks it up and inserts it into the new Time object, the Time part saves incorrectly as 00:00:00</p> <p>I can also confirm that, after the test has run, if I check the db for the record that had been tested, the time is incorrectly saved as 00:00:00 (just in case you were suspecting something with rspec's comaprison or db retrieval was off :) )</p> <p>I would love to get to the bottom of this - its is really frustrating me. Especially considering I don't really care about the date (but I would like to solve this because it has piqued my interest now ;) )</p> <p>Also, am open to suggestions if there is a better way to implement saving a time to the db. Thanks!</p> <p>life_dm.rb</p> <pre><code>require "rubygems" require "json" require "sqlite3" require "data_mapper" require "bigdecimal" DataMapper::setup(:default, "sqlite3://#{Dir.pwd}../spec/resources/test.db") class Sleep include DataMapper::Resource property :id, Integer, :key =&gt; true #easier to get methods when key is id vs week property :wake_time, Time end DataMapper.finalize.auto_migrate! </code></pre> <p>sleep.rb</p> <pre><code>def update_sleep_data (id,wake_time) #I have also tried saving the time as an sql date/time string #i.e :wake_time =&gt; "2013-01-04 #{wake_time[0..1]}:#{wake_time[2..3]}" #but get the same result with rspec getting Sleep.create(:id =&gt; id, :wake_time =&gt; Time.new(2013,01,04,wake_time[0..1].to_i,wake_time[2..3].to_i)) end </code></pre> <p>sleep_spec.rb</p> <pre><code>require 'data_mapper' require_relative '../../data/life_dm' require_relative '../../methods/sleep' describe "sleep table" do it "saves info about sleep to the db" do @id = 1 @wake_time = "0730" update_sleep_data(@id, @wake_time) sleep_1 = Sleep.get 1 sleep_1[:id].should eql 1 sleep_1[:wake_time].should eql Time.new(2013,01,04,07,30,00) end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload