simplydb 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- require 'simplydb/extensions'
4
-
5
- describe SimplyDB::Extensions do
6
- include SimplyDB::Extensions
7
-
8
- it "should underscore a string" do
9
- underscore("MyDomain").should == 'my_domain'
10
- end
11
-
12
- it "should correctly escape a string for URI encoding" do
13
- escape_value("select color from MyDomain where color = 'blue'").should == 'select%20color%20from%20MyDomain%20where%20color%20%3D%20%27blue%27'
14
- end
15
- end
@@ -1,214 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- require 'simplydb/record/base'
4
-
5
- describe SimplyDB::Record::Base do
6
- before do
7
- #need to reset the class each time
8
- Object.send(:remove_const, :People) if Object.const_defined?(:People)
9
- class People < SimplyDB::Record::Base; end
10
-
11
- @attributes = {
12
- 'name' => 'Joe Smith',
13
- 'age' => "25"
14
- }
15
- end
16
-
17
- describe "setting connection credentials" do
18
- it "should be able to set connection credentials" do
19
- People.establish_connection({
20
- :access_key => access_key,
21
- :secret_key => secret_key,
22
- :force => false
23
- })
24
- People.connection.should == {
25
- :access_key => access_key,
26
- :secret_key => secret_key,
27
- :force => false
28
- }
29
- end
30
- it "should inherit from its parent" do
31
- SimplyDB::Record::Base.establish_connection({
32
- :access_key => access_key,
33
- :secret_key => secret_key,
34
- :force => true
35
- })
36
- People.establish_connection
37
- People.connection.should == {
38
- :access_key => access_key,
39
- :secret_key => secret_key,
40
- :force => true
41
- }
42
- end
43
- end
44
-
45
- describe "domain specific functions" do
46
- context "specifying a domain name" do
47
- it "should set default domain name" do
48
- People.domain_name.should == 'people'
49
- end
50
- it "should set a domain name" do
51
- People.set_domain_name("person")
52
- People.domain_name.should == "person"
53
- end
54
- end
55
- describe "while setting up a domain" do
56
- it "should be able to create the domain" do
57
- People.interface.should_receive(:create_domain).with('people').once.and_return(true)
58
- People.create_domain.should be_true
59
- end
60
-
61
- describe "check the existance of the domain" do
62
- it "should not exist" do
63
- People.interface.should_receive(:domain_metadata).with('people').once.and_raise(SimplyDB::Error::NoSuchDomain)
64
- People.domain_exists?.should be_false
65
- end
66
- it "should exist" do
67
- People.interface.should_receive(:domain_metadata).with('people').once.and_return({
68
- 'ItemCount' => '195078',
69
- 'ItemNamesSizeBytes' => '2586634',
70
- 'AttributeNameCount' => '12',
71
- 'AttributeNamesSizeBytes' => '120',
72
- 'AttributeValueCount' => '3690416',
73
- 'AttributeValuesSizeBytes' => '50149756',
74
- 'Timestamp' => '1225486466'
75
- })
76
- People.domain_exists?.should be_true
77
- end
78
- end
79
-
80
- it "should be able to delete the domain" do
81
- People.interface.should_receive(:delete_domain).with('people').once.and_return(true)
82
- People.delete_domain.should be_true
83
- end
84
- end
85
- end
86
-
87
- describe "#new" do
88
- before do
89
- @person = People.new(@attributes)
90
- end
91
- it "should be able to access the attributes" do
92
- @person[:name].should == 'Joe Smith'
93
- @person[:age].should == "25"
94
- end
95
- it "should have first level access to attributes" do
96
- @person.name.should == 'Joe Smith'
97
- @person.age.should == "25"
98
- end
99
- it "should be able to set the attributes" do
100
- @person[:name] = 'Jane Smith'
101
- @person[:name].should == 'Jane Smith'
102
- @person[:age] = 27
103
- @person[:age].should == "27"
104
- end
105
- it "should have first level access to set attributes" do
106
- @person.name = 'Jane Smith'
107
- @person.name.should == 'Jane Smith'
108
- @person.age = 27
109
- @person.age.should == "27"
110
- end
111
- it "should be a new record" do
112
- @person.new_record?.should be_true
113
- end
114
- it "should be able to retrieve attribute names" do
115
- @person.attribute_names.should == ['age', 'name']
116
- end
117
- it "should not have a value for item_name" do
118
- @person.item_name.should be_nil
119
- end
120
- it "should be able to set a value for item_name" do
121
- @person.item_name = "hello world"
122
- @person.item_name.should == "hello world"
123
- end
124
- end
125
-
126
- describe "attributes" do
127
- before do
128
- @person = People.new(@attributes)
129
- end
130
- it "should raise an exception if an attribute doesn't exist" do
131
- lambda {
132
- @person.fake_attribute_name
133
- }.should raise_error(NoMethodError)
134
- end
135
- end
136
-
137
- describe "#create" do
138
- it "should have saved the item" do
139
- People.interface.should_receive(:put_attributes).with("people", "1234", @attributes, anything, anything).and_return(true)
140
- UUIDTools::UUID.should_receive(:random_create).and_return("1234")
141
- @person = People.create(@attributes)
142
- @person.new_record?.should be_false
143
- @person.item_name.should == "1234"
144
- end
145
- end
146
-
147
- describe "#save" do
148
- before do
149
- @person = People.new(@attributes)
150
- end
151
- context "saving the attributes to domain" do
152
- it "should save successfully" do
153
- People.interface.should_receive(:put_attributes).with("people", "1234", @attributes, anything, anything).and_return(true)
154
- @person.item_name = "1234"
155
- @person.save.should == true
156
- @person.new_record?.should be_false
157
- end
158
- context "should save unsuccessfully" do
159
- it "should complain about missing item_name" do
160
- lambda {
161
- @person.save
162
- }.should raise_error(SimplyDB::Record::MissingItemName)
163
- end
164
- end
165
- end
166
- it "should not change the values of the attributes" do
167
- People.interface.should_receive(:put_attributes).with("people", "1234", @attributes, anything, anything).and_return(true)
168
- lambda {
169
- @person.item_name = "1234"
170
- @person.save
171
- }.should_not change { @person.attributes}
172
- end
173
- it "should replace all attributes item on domain" do
174
- People.interface.should_receive(:put_attributes).with("people", "1234", @attributes, anything, true).and_return(true)
175
- @person.item_name = "1234"
176
- @person.save(true)
177
- end
178
- end
179
-
180
- describe "#destroy" do
181
- before do
182
- @person = People.new(@attributes)
183
- @person.item_name = "1234"
184
- People.interface.should_receive(:put_attributes).with(anything, anything, anything, anything, anything).and_return(true)
185
- @person.save
186
- end
187
- it "should successfully destroy an object" do
188
- People.interface.should_receive(:delete_attributes).with("people", "1234")
189
- @person.destroy.should == @person
190
- @person.should be_frozen
191
- end
192
- end
193
-
194
- describe "#find" do
195
- it "should load the item by item_name from domain" do
196
- People.interface.should_receive(:get_attributes).with("people","1234").and_return(@attributes)
197
- @person = People.find("1234")
198
- @person.attributes.should == @attributes
199
- @person.new_record?.should be_false
200
- end
201
-
202
- it "should raise ItemNotFound" do
203
- People.interface.should_receive(:get_attributes).with("people","1234").and_return({})
204
- lambda {
205
- @person = People.find("1234")
206
- }.should raise_error(SimplyDB::Record::ItemNotFound)
207
- end
208
- end
209
-
210
- describe "#find_by_select" do
211
- it "should return an empty array if nothing was found"
212
- it "should return a has of initialized items"
213
- end
214
- end
data/spec/spec.opts DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --backtrace