This repository has been archived by the owner on Nov 30, 2018. It is now read-only.
/
row_operation_spec.rb
75 lines (61 loc) · 2.34 KB
/
row_operation_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
describe Stargate::Operation::RowOperation do
before :all do
url = ENV["STARGATE_URL"].nil? ? "http://localhost:8080" : ENV["STARGATE_URL"]
@client = Stargate::Client.new(url)
table = @client.create_table("test-stargate-client", "col1")
end
it "should create a row called 'row1'" do
lambda {
@client.create_row("test-stargate-client", "row1", nil, { :name => "col1:", :value => "row1-col1" }).should be_true
}.should_not raise_error
end
it "should create a row named 'row2' with timestamp value" do
timestamp = (Time.now - (5*60)).to_i
lambda {
@client.create_row("test-stargate-client", "row2", timestamp, { :name => "col1:cell1", :value => "row2-col1-cell1" }).should be_true
}.should_not raise_error
row = @client.show_row("test-stargate-client", "row2")
row.should be_a_kind_of(Stargate::Model::Row)
row.name.should == "row2"
columns = row.columns
columns.size.should == 1
columns.first.name.should == "col1:cell1"
columns.first.value.should == "row2-col1-cell1"
columns.first.timestamp.should == timestamp
end
it "should show the rows 'row1'" do
row = @client.show_row("test-stargate-client", "row1")
row.should.is_a? Stargate::Model::Row
row.table_name.should == "test-stargate-client"
row.name.should == "row1"
row.columns.size.should == 1
row.columns.each do |col|
col.should.is_a? Stargate::Model::Column
col.name.should == "col1:"
col.value.should == "row1-col1"
end
end
it "should delete rows when timestamps are defined" do
row1 = @client.show_row("test-stargate-client", "row1")
timestamp = row1.columns.map(&:timestamp).uniq.first
lambda {
@client.delete_row('test-stargate-client', 'row1', timestamp).should be_true
}.should_not raise_error
lambda {
@client.show_row('test-stargate-client', 'row1')
}.should raise_error
end
it "should delete rows without a timestamp provided" do
row2 = @client.show_row("test-stargate-client", "row2")
lambda {
@client.delete_row('test-stargate-client', 'row2').should be_true
}.should_not raise_error
lambda {
@client.show_row('test-stargate-client', 'row2')
}.should raise_error
end
after :all do
table = @client.destroy_table("")
end
end