spec/validation_spec.rb in cassandra-cql-1.0.1 vs spec/validation_spec.rb in cassandra-cql-1.0.2

- old
+ new

@@ -7,11 +7,12 @@ @connection = setup_cassandra_connection end def create_and_fetch_column(column_family, value) @connection.execute("insert into #{column_family} (id, test_column) values (?, ?)", 'test', value) - return @connection.execute("select test_column from #{column_family} where id = ?", 'test').fetch[0] + res = @connection.execute("select test_column from #{column_family} where id = ?", 'test') + return res.fetch[0] end def create_column_family(name, test_column_type, opts="") if !@connection.schema.column_family_names.include?(name) @connection.execute("CREATE COLUMNFAMILY #{name} (id text PRIMARY KEY, test_column #{test_column_type}) #{opts}") @@ -195,11 +196,22 @@ context "with timestamp validation" do let(:cf_name) { "validation_cf_timestamp" } before(:each) { create_column_family(cf_name, 'timestamp') } it "should return a timestamp" do - uuid = UUID.new - #create_and_fetch_column(cf_name, uuid).should eq(uuid) + ts = Time.new + res = create_and_fetch_column(cf_name, ts) + res.to_f.should be_within(0.001).of(ts.to_f) + res.class.should eq(Time) + end + + it "should return a timestamp given a date" do + date = Date.today + res = create_and_fetch_column(cf_name, date) + [:year, :month, :day].each do |sym| + res.send(sym).should eq(date.send(sym)) + end + res.class.should eq(Time) end end context "with uuid validation" do let(:cf_name) { "validation_cf_uuid" } \ No newline at end of file