simplydb 0.0.0

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.
@@ -0,0 +1,198 @@
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
+ class People < SimplyDB::Record::Base; end
8
+ People.set_domain_name(nil) #have to reset the domain name each time
9
+
10
+ @attributes = {
11
+ 'name' => 'Joe Smith',
12
+ 'age' => 25
13
+ }
14
+ end
15
+
16
+ it "should be able to set connection credentials" do
17
+ People.establish_connection({
18
+ :access_key => access_key,
19
+ :secret_key => secret_key,
20
+ :force => false
21
+ })
22
+ People.connection.should == {
23
+ :access_key => access_key,
24
+ :secret_key => secret_key,
25
+ :force => false
26
+ }
27
+ end
28
+
29
+ describe "domain specific functions" do
30
+ context "specifying a domain name" do
31
+ it "should set default domain name" do
32
+ People.domain_name.should == 'people'
33
+ end
34
+ it "should set a domain name" do
35
+ People.set_domain_name("person")
36
+ People.domain_name.should == "person"
37
+ end
38
+ end
39
+ describe "while setting up a domain" do
40
+ it "should be able to create the domain" do
41
+ People.interface.should_receive(:create_domain).with('people').once.and_return(true)
42
+ People.create_domain.should == true
43
+ end
44
+
45
+ describe "check the existance of the domain" do
46
+ it "should not exist" do
47
+ People.interface.should_receive(:domain_metadata).with('people').once.and_raise(SimplyDB::Error::NoSuchDomain)
48
+ People.domain_exists?.should == false
49
+ end
50
+ it "should exist" do
51
+ People.interface.should_receive(:domain_metadata).with('people').once.and_return({
52
+ 'ItemCount' => '195078',
53
+ 'ItemNamesSizeBytes' => '2586634',
54
+ 'AttributeNameCount' => '12',
55
+ 'AttributeNamesSizeBytes' => '120',
56
+ 'AttributeValueCount' => '3690416',
57
+ 'AttributeValuesSizeBytes' => '50149756',
58
+ 'Timestamp' => '1225486466'
59
+ })
60
+ People.domain_exists?.should == true
61
+ end
62
+ end
63
+
64
+ it "should be able to delete the domain" do
65
+ People.interface.should_receive(:delete_domain).with('people').once.and_return(true)
66
+ People.delete_domain.should == true
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "#new" do
72
+ before do
73
+ @person = People.new(@attributes)
74
+ end
75
+ it "should be able to access the attributes" do
76
+ @person[:name].should == 'Joe Smith'
77
+ @person[:age].should == 25
78
+ end
79
+ it "should have first level access to attributes" do
80
+ @person.name.should == 'Joe Smith'
81
+ @person.age.should == 25
82
+ end
83
+ it "should be able to set the attributes" do
84
+ @person[:name] = 'Jane Smith'
85
+ @person[:name].should == 'Jane Smith'
86
+ @person[:age] = 27
87
+ @person[:age].should == 27
88
+ end
89
+ it "should have first level access to set attributes" do
90
+ @person.name = 'Jane Smith'
91
+ @person.name.should == 'Jane Smith'
92
+ @person.age = 27
93
+ @person.age.should == 27
94
+ end
95
+ it "should be a new record" do
96
+ @person.new_record?.should == true
97
+ end
98
+ it "should be able to retrieve attribute names" do
99
+ @person.attribute_names.should == ['age', 'name']
100
+ end
101
+ it "should not have a value for item_name" do
102
+ @person.item_name.should be_nil
103
+ end
104
+ it "should be able to set a value for item_name" do
105
+ @person.item_name = "hello world"
106
+ @person.item_name.should == "hello world"
107
+ end
108
+ end
109
+
110
+ describe "attributes" do
111
+ before do
112
+ @person = People.new(@attributes)
113
+ end
114
+ it "should raise an exception if an attribute doesn't exist" do
115
+ lambda {
116
+ @person.fake_attribute_name
117
+ }.should raise_error(NoMethodError)
118
+ end
119
+ end
120
+
121
+ describe "#create" do
122
+ it "should have saved the item" do
123
+ People.interface.should_receive(:put_attributes).with("people", "1234", {'name'=>'Joe Smith', 'age'=>25}, anything, anything).and_return(true)
124
+ UUIDTools::UUID.should_receive(:random_create).and_return("1234")
125
+ @person = People.create(@attributes)
126
+ @person.new_record?.should == false
127
+ @person.item_name.should == "1234"
128
+ end
129
+ end
130
+
131
+ describe "#save" do
132
+ before do
133
+ @person = People.new(@attributes)
134
+ end
135
+ context "saving the attributes to domain" do
136
+ it "should save successfully" do
137
+ People.interface.should_receive(:put_attributes).with("people", "1234", {'name'=>'Joe Smith', 'age'=>25}, anything, anything).and_return(true)
138
+ @person.item_name = "1234"
139
+ @person.save.should == true
140
+ @person.new_record?.should == false
141
+ end
142
+ context "should save unsuccessfully" do
143
+ it "should complain about missing item_name" do
144
+ lambda {
145
+ @person.save
146
+ }.should raise_error(SimplyDB::Record::MissingItemName)
147
+ end
148
+ end
149
+ end
150
+ it "should not change the values of the attributes" do
151
+ People.interface.should_receive(:put_attributes).with("people", "1234", {'name'=>'Joe Smith', 'age'=>25}, anything, anything).and_return(true)
152
+ lambda {
153
+ @person.item_name = "1234"
154
+ @person.save
155
+ }.should_not change { @person.attributes}
156
+ end
157
+ it "should replace all attributes item on domain" do
158
+ People.interface.should_receive(:put_attributes).with("people", "1234", {'name'=>'Joe Smith', 'age'=>25}, anything, true).and_return(true)
159
+ @person.item_name = "1234"
160
+ @person.save(true)
161
+ end
162
+ end
163
+
164
+ describe "#destroy" do
165
+ before do
166
+ @person = People.new(@attributes)
167
+ @person.item_name = "1234"
168
+ People.interface.should_receive(:put_attributes).with(anything, anything, anything, anything, anything).and_return(true)
169
+ @person.save
170
+ end
171
+ it "should successfully destroy an object" do
172
+ People.interface.should_receive(:delete_attributes).with("people", "1234")
173
+ @person.destroy.should == @person
174
+ @person.should be_frozen
175
+ end
176
+ end
177
+
178
+ describe "#find" do
179
+ it "should load the item by item_name from domain" do
180
+ People.interface.should_receive(:get_attributes).with("people","1234").and_return(@attributes)
181
+ @person = People.find("1234")
182
+ @person.attributes.should == @attributes
183
+ end
184
+
185
+ it "should raise ItemNotFound" do
186
+ People.interface.should_receive(:get_attributes).with("people","1234").and_return({})
187
+ lambda {
188
+ @person = People.find("1234")
189
+ }.should raise_error(SimplyDB::Record::ItemNotFound)
190
+ end
191
+ end
192
+
193
+ describe "#find" do
194
+ end
195
+
196
+ describe "#find_by_select" do
197
+ end
198
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --backtrace
@@ -0,0 +1,24 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'simplydb'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ require 'rubygems'
8
+ require 'timecop'
9
+
10
+ Spec::Runner.configure do |config|
11
+ def access_key
12
+ return '12345'
13
+ end
14
+
15
+ def secret_key
16
+ return '67890'
17
+ end
18
+
19
+ def run_today(time = Time.gm(2008, 9, 1, 12, 0, 0))
20
+ Timecop.freeze(time) do
21
+ yield
22
+ end
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplydb
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - JT Archie
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-25 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: typhoeus
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 45
46
+ segments:
47
+ - 0
48
+ - 1
49
+ - 27
50
+ version: 0.1.27
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: nokogiri
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 1
64
+ - 4
65
+ - 2
66
+ version: 1.4.2
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: uuidtools
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 9
78
+ segments:
79
+ - 2
80
+ - 1
81
+ - 1
82
+ version: 2.1.1
83
+ type: :runtime
84
+ version_requirements: *id004
85
+ description: A minimal interface to Amazon SimpleDB that has separation of interfaces. From the low level HTTP request access to high level Ruby abstraction ORM.
86
+ email: jtarchie@gmail.com
87
+ executables: []
88
+
89
+ extensions: []
90
+
91
+ extra_rdoc_files:
92
+ - LICENSE
93
+ - README.rdoc
94
+ files:
95
+ - .document
96
+ - .gitignore
97
+ - LICENSE
98
+ - README.rdoc
99
+ - Rakefile
100
+ - VERSION
101
+ - examples/interface.rb
102
+ - examples/record.rb
103
+ - lib/simplydb.rb
104
+ - lib/simplydb/client.rb
105
+ - lib/simplydb/clients/typhoeus.rb
106
+ - lib/simplydb/error.rb
107
+ - lib/simplydb/extensions.rb
108
+ - lib/simplydb/interface.rb
109
+ - lib/simplydb/record/base.rb
110
+ - simplydb.gemspec
111
+ - spec/client_spec.rb
112
+ - spec/error_spec.rb
113
+ - spec/extensions_spec.rb
114
+ - spec/interface_spec.rb
115
+ - spec/record/base_spec.rb
116
+ - spec/spec.opts
117
+ - spec/spec_helper.rb
118
+ has_rdoc: true
119
+ homepage: http://github.com/jtarchie/simplydb
120
+ licenses: []
121
+
122
+ post_install_message:
123
+ rdoc_options:
124
+ - --charset=UTF-8
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ hash: 3
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ hash: 3
142
+ segments:
143
+ - 0
144
+ version: "0"
145
+ requirements: []
146
+
147
+ rubyforge_project:
148
+ rubygems_version: 1.3.7
149
+ signing_key:
150
+ specification_version: 3
151
+ summary: A minimal interface to Amazon SimpleDB.
152
+ test_files:
153
+ - spec/client_spec.rb
154
+ - spec/error_spec.rb
155
+ - spec/extensions_spec.rb
156
+ - spec/interface_spec.rb
157
+ - spec/record/base_spec.rb
158
+ - spec/spec_helper.rb
159
+ - examples/interface.rb
160
+ - examples/record.rb