activerecord-simpledb-adapter 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +14 -0
- data/Gemfile.lock +108 -0
- data/README.md +6 -1
- data/activerecord-simpledb-adapter.gemspec +23 -3
- data/lib/active_record/connection_adapters/simpledb_adapter.rb +37 -2
- data/lib/activerecord-simpledb-adapter.rb +4 -0
- data/lib/generators/active_record/model/model_generator.rb +30 -0
- data/lib/generators/active_record/model/templates/model.rb +13 -0
- data/lib/tasks/simpledb.rake +62 -8
- data/spec/active_record/defaults_spec.rb +35 -0
- data/spec/assets/db/seeds.rb +1 -0
- data/spec/generators/model_spec.rb +17 -0
- data/spec/tasks/rake_spec.rb +82 -0
- metadata +85 -11
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
gem "rspec", "~> 2.3.0"
|
5
|
+
gem "bundler", "~> 1.0.0"
|
6
|
+
gem "jeweler", "~> 1.5.2"
|
7
|
+
gem "rcov", ">= 0"
|
8
|
+
gem "aws"
|
9
|
+
gem "activerecord"
|
10
|
+
gem "activesupport"
|
11
|
+
gem 'genspec', '0.2.0.prerails3.2'
|
12
|
+
gem 'thor'
|
13
|
+
gem 'rails'
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.3)
|
6
|
+
actionpack (= 3.0.3)
|
7
|
+
mail (~> 2.2.9)
|
8
|
+
actionpack (3.0.3)
|
9
|
+
activemodel (= 3.0.3)
|
10
|
+
activesupport (= 3.0.3)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.4)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.13)
|
16
|
+
rack-test (~> 0.5.6)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.3)
|
19
|
+
activesupport (= 3.0.3)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.4)
|
22
|
+
activerecord (3.0.3)
|
23
|
+
activemodel (= 3.0.3)
|
24
|
+
activesupport (= 3.0.3)
|
25
|
+
arel (~> 2.0.2)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.3)
|
28
|
+
activemodel (= 3.0.3)
|
29
|
+
activesupport (= 3.0.3)
|
30
|
+
activesupport (3.0.3)
|
31
|
+
arel (2.0.6)
|
32
|
+
aws (2.3.34)
|
33
|
+
activesupport
|
34
|
+
http_connection
|
35
|
+
uuidtools
|
36
|
+
xml-simple
|
37
|
+
builder (2.1.2)
|
38
|
+
diff-lcs (1.1.2)
|
39
|
+
erubis (2.6.6)
|
40
|
+
abstract (>= 1.0.0)
|
41
|
+
genspec (0.2.0.prerails3.2)
|
42
|
+
rspec (>= 2.0.0.beta.14)
|
43
|
+
sc-core-ext (>= 1.2.1)
|
44
|
+
git (1.2.5)
|
45
|
+
http_connection (1.4.0)
|
46
|
+
i18n (0.5.0)
|
47
|
+
jeweler (1.5.2)
|
48
|
+
bundler (~> 1.0.0)
|
49
|
+
git (>= 1.2.5)
|
50
|
+
rake
|
51
|
+
mail (2.2.14)
|
52
|
+
activesupport (>= 2.3.6)
|
53
|
+
i18n (>= 0.4.0)
|
54
|
+
mime-types (~> 1.16)
|
55
|
+
treetop (~> 1.4.8)
|
56
|
+
mime-types (1.16)
|
57
|
+
polyglot (0.3.1)
|
58
|
+
rack (1.2.1)
|
59
|
+
rack-mount (0.6.13)
|
60
|
+
rack (>= 1.0.0)
|
61
|
+
rack-test (0.5.7)
|
62
|
+
rack (>= 1.0)
|
63
|
+
rails (3.0.3)
|
64
|
+
actionmailer (= 3.0.3)
|
65
|
+
actionpack (= 3.0.3)
|
66
|
+
activerecord (= 3.0.3)
|
67
|
+
activeresource (= 3.0.3)
|
68
|
+
activesupport (= 3.0.3)
|
69
|
+
bundler (~> 1.0)
|
70
|
+
railties (= 3.0.3)
|
71
|
+
railties (3.0.3)
|
72
|
+
actionpack (= 3.0.3)
|
73
|
+
activesupport (= 3.0.3)
|
74
|
+
rake (>= 0.8.7)
|
75
|
+
thor (~> 0.14.4)
|
76
|
+
rake (0.8.7)
|
77
|
+
rcov (0.9.9)
|
78
|
+
rspec (2.3.0)
|
79
|
+
rspec-core (~> 2.3.0)
|
80
|
+
rspec-expectations (~> 2.3.0)
|
81
|
+
rspec-mocks (~> 2.3.0)
|
82
|
+
rspec-core (2.3.1)
|
83
|
+
rspec-expectations (2.3.0)
|
84
|
+
diff-lcs (~> 1.1.2)
|
85
|
+
rspec-mocks (2.3.0)
|
86
|
+
sc-core-ext (1.2.1)
|
87
|
+
activesupport (>= 2.3.5)
|
88
|
+
thor (0.14.6)
|
89
|
+
treetop (1.4.9)
|
90
|
+
polyglot (>= 0.3.1)
|
91
|
+
tzinfo (0.3.23)
|
92
|
+
uuidtools (2.1.1)
|
93
|
+
xml-simple (1.0.12)
|
94
|
+
|
95
|
+
PLATFORMS
|
96
|
+
ruby
|
97
|
+
|
98
|
+
DEPENDENCIES
|
99
|
+
activerecord
|
100
|
+
activesupport
|
101
|
+
aws
|
102
|
+
bundler (~> 1.0.0)
|
103
|
+
genspec (= 0.2.0.prerails3.2)
|
104
|
+
jeweler (~> 1.5.2)
|
105
|
+
rails
|
106
|
+
rcov
|
107
|
+
rspec (~> 2.3.0)
|
108
|
+
thor
|
data/README.md
CHANGED
@@ -5,23 +5,27 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{activerecord-simpledb-adapter}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ilia Ablamonov", "Alex Gorkunov", "Cloud Castle Inc."]
|
12
|
-
s.date = %q{2011-01-
|
12
|
+
s.date = %q{2011-01-21}
|
13
13
|
s.email = %q{ilia@flamefork.ru}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
16
16
|
"README.md"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
|
+
"Gemfile",
|
20
|
+
"Gemfile.lock",
|
19
21
|
"LICENSE.txt",
|
20
22
|
"README.md",
|
21
23
|
"activerecord-simpledb-adapter.gemspec",
|
22
24
|
"lib/active_record/connection_adapters/simpledb_adapter.rb",
|
23
25
|
"lib/activerecord-simpledb-adapter.rb",
|
24
26
|
"lib/arel/visitors/simpledb.rb",
|
27
|
+
"lib/generators/active_record/model/model_generator.rb",
|
28
|
+
"lib/generators/active_record/model/templates/model.rb",
|
25
29
|
"lib/tasks/simpledb.rake"
|
26
30
|
]
|
27
31
|
s.homepage = %q{http://github.com/cloudcastle/activerecord-simpledb-adapter}
|
@@ -32,11 +36,15 @@ Gem::Specification.new do |s|
|
|
32
36
|
s.test_files = [
|
33
37
|
"spec/active_record/connection_adapters/simpledb_adapter_spec.rb",
|
34
38
|
"spec/active_record/core_actions_spec.rb",
|
39
|
+
"spec/active_record/defaults_spec.rb",
|
35
40
|
"spec/active_record/locking_spec.rb",
|
36
41
|
"spec/active_record/record_attributes_spec.rb",
|
37
42
|
"spec/active_record/validates_spec.rb",
|
38
43
|
"spec/active_record/where_spec.rb",
|
39
|
-
"spec/
|
44
|
+
"spec/assets/db/seeds.rb",
|
45
|
+
"spec/generators/model_spec.rb",
|
46
|
+
"spec/spec_helper.rb",
|
47
|
+
"spec/tasks/rake_spec.rb"
|
40
48
|
]
|
41
49
|
|
42
50
|
if s.respond_to? :specification_version then
|
@@ -51,10 +59,14 @@ Gem::Specification.new do |s|
|
|
51
59
|
s.add_development_dependency(%q<aws>, [">= 0"])
|
52
60
|
s.add_development_dependency(%q<activerecord>, [">= 0"])
|
53
61
|
s.add_development_dependency(%q<activesupport>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<genspec>, ["= 0.2.0.prerails3.2"])
|
63
|
+
s.add_development_dependency(%q<thor>, [">= 0"])
|
64
|
+
s.add_development_dependency(%q<rails>, [">= 0"])
|
54
65
|
s.add_runtime_dependency(%q<aws>, ["~> 2.3.0"])
|
55
66
|
s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.3"])
|
56
67
|
s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.3"])
|
57
68
|
s.add_runtime_dependency(%q<uuidtools>, ["~> 2.1.1"])
|
69
|
+
s.add_runtime_dependency(%q<rails>, ["~> 3.0.3"])
|
58
70
|
else
|
59
71
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
60
72
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
@@ -63,10 +75,14 @@ Gem::Specification.new do |s|
|
|
63
75
|
s.add_dependency(%q<aws>, [">= 0"])
|
64
76
|
s.add_dependency(%q<activerecord>, [">= 0"])
|
65
77
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
78
|
+
s.add_dependency(%q<genspec>, ["= 0.2.0.prerails3.2"])
|
79
|
+
s.add_dependency(%q<thor>, [">= 0"])
|
80
|
+
s.add_dependency(%q<rails>, [">= 0"])
|
66
81
|
s.add_dependency(%q<aws>, ["~> 2.3.0"])
|
67
82
|
s.add_dependency(%q<activerecord>, ["~> 3.0.3"])
|
68
83
|
s.add_dependency(%q<activesupport>, ["~> 3.0.3"])
|
69
84
|
s.add_dependency(%q<uuidtools>, ["~> 2.1.1"])
|
85
|
+
s.add_dependency(%q<rails>, ["~> 3.0.3"])
|
70
86
|
end
|
71
87
|
else
|
72
88
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
@@ -76,10 +92,14 @@ Gem::Specification.new do |s|
|
|
76
92
|
s.add_dependency(%q<aws>, [">= 0"])
|
77
93
|
s.add_dependency(%q<activerecord>, [">= 0"])
|
78
94
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
95
|
+
s.add_dependency(%q<genspec>, ["= 0.2.0.prerails3.2"])
|
96
|
+
s.add_dependency(%q<thor>, [">= 0"])
|
97
|
+
s.add_dependency(%q<rails>, [">= 0"])
|
79
98
|
s.add_dependency(%q<aws>, ["~> 2.3.0"])
|
80
99
|
s.add_dependency(%q<activerecord>, ["~> 3.0.3"])
|
81
100
|
s.add_dependency(%q<activesupport>, ["~> 3.0.3"])
|
82
101
|
s.add_dependency(%q<uuidtools>, ["~> 2.1.1"])
|
102
|
+
s.add_dependency(%q<rails>, ["~> 3.0.3"])
|
83
103
|
end
|
84
104
|
end
|
85
105
|
|
@@ -88,6 +88,7 @@ module ActiveRecord
|
|
88
88
|
:server => config[:host],
|
89
89
|
:port => config[:port],
|
90
90
|
:protocol => config[:protocol],
|
91
|
+
:connection_mode => :per_thread,
|
91
92
|
:logger => SimpleDBLogger.new(logger)
|
92
93
|
},
|
93
94
|
config
|
@@ -98,12 +99,37 @@ module ActiveRecord
|
|
98
99
|
def self.columns_definition options = {}
|
99
100
|
table_definition = ConnectionAdapters::SimpleDbTableDifinition.new(options[:collection_column_name] || DEFAULT_COLLECTION_COLUMN_NAME)
|
100
101
|
table_definition.primary_key(Base.get_primary_key(table_name.to_s.singularize))
|
102
|
+
|
103
|
+
alias_method_chain :initialize, :defaults
|
104
|
+
|
101
105
|
yield table_definition if block_given?
|
102
106
|
|
103
107
|
ConnectionAdapters::SimpleDBAdapter.set_collection_columns table_name, table_definition
|
104
108
|
end
|
105
109
|
|
110
|
+
def initialize_with_defaults(attrs = nil)
|
111
|
+
initialize_without_defaults(attrs) do
|
112
|
+
safe_attribute_names = []
|
113
|
+
if attrs
|
114
|
+
stringified_attrs = attrs.stringify_keys
|
115
|
+
safe_attrs = sanitize_for_mass_assignment(stringified_attrs)
|
116
|
+
safe_attribute_names = safe_attrs.keys.map { |x| x.to_s }
|
117
|
+
end
|
106
118
|
|
119
|
+
ActiveRecord::Base.connection.columns_definition(self.class.table_name).columns_with_defaults.each do |column|
|
120
|
+
if !safe_attribute_names.any? { |attr_name| attr_name =~ /^#{column.name}($|\()/ }
|
121
|
+
value = if column.default.is_a? Proc
|
122
|
+
column.default.call(self)
|
123
|
+
else
|
124
|
+
column.default
|
125
|
+
end
|
126
|
+
__send__("#{column.name}=", value)
|
127
|
+
changed_attributes.delete(column.name)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
yield(self) if block_given?
|
131
|
+
end
|
132
|
+
end
|
107
133
|
|
108
134
|
end
|
109
135
|
|
@@ -179,10 +205,14 @@ module ActiveRecord
|
|
179
205
|
|
180
206
|
def column(name, type, options = {})
|
181
207
|
raise ConfigurationError, %Q(column '#{collection_column_name}' reserved, please change column name) if name.to_s == collection_column_name
|
182
|
-
@columns << SimpleDBColumn.new(name.to_s, type.to_sym, options[:limit], options[:precision], options[:to])
|
208
|
+
@columns << SimpleDBColumn.new(name.to_s, type.to_sym, options[:limit], options[:precision], options[:to], options[:default])
|
183
209
|
self
|
184
210
|
end
|
185
211
|
|
212
|
+
def columns_with_defaults
|
213
|
+
@columns_with_defaults ||= @columns.select { |column| column.default.present? }
|
214
|
+
end
|
215
|
+
|
186
216
|
end
|
187
217
|
|
188
218
|
class SimpleDBColumn < Column
|
@@ -190,10 +220,11 @@ module ActiveRecord
|
|
190
220
|
DEFAULT_NUMBER_LIMIT = 4
|
191
221
|
DEFAULT_FLOAT_PRECISION = 4
|
192
222
|
|
193
|
-
def initialize(name, type, limit = nil, pricision = nil, to = nil)
|
223
|
+
def initialize(name, type, limit = nil, pricision = nil, to = nil, default = nil)
|
194
224
|
super name, nil, type, true
|
195
225
|
@limit = limit if limit.present?
|
196
226
|
@precision = precision if precision.present?
|
227
|
+
@default = default
|
197
228
|
@to = to
|
198
229
|
end
|
199
230
|
|
@@ -409,6 +440,10 @@ module ActiveRecord
|
|
409
440
|
@connection.delete_domain domain_name
|
410
441
|
end
|
411
442
|
|
443
|
+
def list_domains
|
444
|
+
@connection.list_domains[:domains]
|
445
|
+
end
|
446
|
+
|
412
447
|
private
|
413
448
|
|
414
449
|
def generate_id
|
@@ -4,6 +4,10 @@ module ActiveRecordSimpledbAdapter
|
|
4
4
|
load 'tasks/simpledb.rake'
|
5
5
|
end
|
6
6
|
|
7
|
+
generators do
|
8
|
+
require 'generators/active_record/model/model_generator'
|
9
|
+
end
|
10
|
+
|
7
11
|
ActiveSupport.on_load(:active_record) do
|
8
12
|
require 'active_record/connection_adapters/simpledb_adapter'
|
9
13
|
require 'arel/visitors/simpledb'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module Generators
|
5
|
+
class ModelGenerator < Base
|
6
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
7
|
+
|
8
|
+
check_class_collision
|
9
|
+
|
10
|
+
class_option :timestamps, :type => :boolean
|
11
|
+
class_option :parent, :type => :string, :desc => "The parent class for the generated model"
|
12
|
+
|
13
|
+
def create_model_file
|
14
|
+
template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
15
|
+
end
|
16
|
+
|
17
|
+
hook_for :test_framework
|
18
|
+
|
19
|
+
def self.source_root
|
20
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
21
|
+
end
|
22
|
+
protected
|
23
|
+
|
24
|
+
def parent_class_name
|
25
|
+
options[:parent] || "ActiveRecord::Base"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class <%= class_name %> < <%= parent_class_name.classify %>
|
2
|
+
columns_definition do |c|
|
3
|
+
<% for attribute in attributes -%>
|
4
|
+
c.<%= attribute.type %> :<%= attribute.name %>
|
5
|
+
<% end -%>
|
6
|
+
<% if options[:timestamps] %>
|
7
|
+
c.timestamps
|
8
|
+
<% end -%>
|
9
|
+
end
|
10
|
+
<% attributes.select {|attr| attr.reference? }.each do |attribute| -%>
|
11
|
+
belongs_to :<%= attribute.name %>
|
12
|
+
<% end -%>
|
13
|
+
end
|
data/lib/tasks/simpledb.rake
CHANGED
@@ -1,17 +1,71 @@
|
|
1
|
-
|
2
|
-
Rake::Task
|
1
|
+
#clear all predefined db tasks
|
2
|
+
Rake::Task.tasks.select{ |task| task.name.match /db:/ }.each { |task| task.clear }
|
3
3
|
namespace :db do
|
4
|
-
|
5
|
-
|
4
|
+
desc "Create the SimpleDB domain"
|
5
|
+
task :create => :environment do
|
6
|
+
create_domain
|
6
7
|
end
|
7
8
|
|
9
|
+
desc "Drop the SimpleDB domain"
|
10
|
+
task :drop => :environment do
|
11
|
+
con = ActiveRecord::Base.connection
|
12
|
+
if con.list_domains.include? domain_name
|
13
|
+
con.delete_domain(domain_name)
|
14
|
+
log "Domain \"#{domain_name}\" was dropped"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Drop and create the SimpleDB domain"
|
19
|
+
task :recreate => [:drop, :create]
|
20
|
+
|
21
|
+
desc "Load the seed data from db/seeds.rb"
|
8
22
|
task :seed => :environment do
|
9
23
|
seed_file = File.join(Rails.root, 'db', 'seeds.rb')
|
10
|
-
|
24
|
+
if File.exist?(seed_file)
|
25
|
+
load(seed_file)
|
26
|
+
log "Data from seeds file was pushed to domain"
|
27
|
+
else
|
28
|
+
log "Seeds file (#{seed_file}) not found"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Re-create the domain and initialize with the seed data"
|
33
|
+
task :setup => [:recreate, :seed]
|
34
|
+
|
35
|
+
namespace :collection do
|
36
|
+
desc "Clear all data for collection by name"
|
37
|
+
task :clear, [:name, :ccn] => :environment do |t, args|
|
38
|
+
ccn = args[:ccn] || 'collection'
|
39
|
+
name = args[:name]
|
40
|
+
if name.present?
|
41
|
+
rows = ActiveRecord::Base.connection.select_all("SELECT id FROM `#{domain_name}` WHERE `#{ccn}` = '#{name}'")
|
42
|
+
rows.each do |row|
|
43
|
+
ActiveRecord::Base.connection.execute({
|
44
|
+
:action => :delete,
|
45
|
+
:wheres => {:id => row['id']}
|
46
|
+
})
|
47
|
+
log "#{row.count} items was deleted."
|
48
|
+
end
|
49
|
+
else
|
50
|
+
log "Please put collection name as \"name=<collection_name>\""
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_domain
|
56
|
+
ActiveRecord::Base.connection.create_domain(domain_name)
|
57
|
+
log "Sdb domain \"#{domain_name}\" was created"
|
58
|
+
end
|
59
|
+
|
60
|
+
def config
|
61
|
+
@config ||= ActiveRecord::Base.configurations[Rails.env]
|
62
|
+
end
|
63
|
+
|
64
|
+
def domain_name
|
65
|
+
config[:domain_name] || config['domain_name']
|
11
66
|
end
|
12
67
|
|
13
|
-
def
|
14
|
-
|
15
|
-
ActiveRecord::Base.connection.create_domain(config['domain_name'])
|
68
|
+
def log text
|
69
|
+
Rails.logger.info text
|
16
70
|
end
|
17
71
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "SimpleDBAdapter ActiveRecord default values for attributes" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
7
|
+
ActiveRecord::Base.establish_connection($config)
|
8
|
+
ActiveRecord::Base.connection.create_domain($config[:domain_name])
|
9
|
+
end
|
10
|
+
|
11
|
+
after :each do
|
12
|
+
ActiveRecord::Base.connection.delete_domain($config[:domain_name])
|
13
|
+
end
|
14
|
+
|
15
|
+
class ModelWithDefaults < ActiveRecord::Base
|
16
|
+
columns_definition do |c|
|
17
|
+
c.string :p1, :default => 'payload_string1'
|
18
|
+
c.string :p2, :default => lambda { "payload_string2" }
|
19
|
+
c.integer :p3, :default => 10
|
20
|
+
c.float :p4, :default => 10.05
|
21
|
+
c.boolean :p5, :default => true
|
22
|
+
c.string :p6
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should correct sets after create new instance of model" do
|
27
|
+
m = ModelWithDefaults.new
|
28
|
+
m.p1.should == "payload_string1"
|
29
|
+
m.p2.should == "payload_string2"
|
30
|
+
m.p3.should == 10
|
31
|
+
m.p4.should == 10.05
|
32
|
+
m.p5.should be_true
|
33
|
+
m.p6.should be_nil
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Person.create!(:login => "admin")
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rails'
|
3
|
+
require 'rails/generators'
|
4
|
+
require 'generators/active_record/model/model_generator'
|
5
|
+
require 'genspec'
|
6
|
+
describe :model do
|
7
|
+
context "with a name argument" do
|
8
|
+
with_args "foo", "name:string", "year:integer", "--orm=active_record"
|
9
|
+
|
10
|
+
it "should generate a model called 'foo' with two columns" do
|
11
|
+
subject.should generate("app/models/foo.rb") { |content|
|
12
|
+
content.should =~ /class Foo < ActiveRecord\:\:Base/
|
13
|
+
content.should =~ /columns_definition do \|c\|\n c.string :name\n c.integer :year\n end/
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rake'
|
3
|
+
require 'rails'
|
4
|
+
|
5
|
+
DOMAIN = CONNECTION_PARAMS[:domain_name]
|
6
|
+
|
7
|
+
def delete_domain_if_exist
|
8
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
9
|
+
con = ActiveRecord::Base.connection
|
10
|
+
con.delete_domain(DOMAIN) if con.list_domains.include? DOMAIN
|
11
|
+
end
|
12
|
+
|
13
|
+
def recreate_domain
|
14
|
+
delete_domain_if_exist
|
15
|
+
ActiveRecord::Base.connection.create_domain DOMAIN
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "gem rake tasks" do
|
19
|
+
before do
|
20
|
+
@rake = Rake::Application.new
|
21
|
+
Rake.application = @rake
|
22
|
+
Rake.application.rake_require "tasks/simpledb"
|
23
|
+
Rake::Task.define_task(:environment)
|
24
|
+
ActiveRecord::Base.stub!(:configurations).and_return({"development" => CONNECTION_PARAMS})
|
25
|
+
Rails.stub!(:env).and_return("development")
|
26
|
+
Rails.stub!(:logger).and_return(Logger.new(STDOUT))
|
27
|
+
Rails.stub!(:root).and_return(File.dirname(__FILE__) + "/../assets")
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "db:create" do
|
31
|
+
before do
|
32
|
+
@task_name = "db:create"
|
33
|
+
delete_domain_if_exist
|
34
|
+
end
|
35
|
+
it "should create sdb domain" do
|
36
|
+
@rake[@task_name].invoke
|
37
|
+
ActiveRecord::Base.connection.list_domains.should include(DOMAIN)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "db:drop" do
|
42
|
+
before do
|
43
|
+
@task_name = "db:drop"
|
44
|
+
recreate_domain
|
45
|
+
end
|
46
|
+
it "should drop sdb domain" do
|
47
|
+
@rake[@task_name].invoke
|
48
|
+
ActiveRecord::Base.connection.list_domains.should_not include(DOMAIN)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "db:seed" do
|
53
|
+
before do
|
54
|
+
@task_name = "db:seed"
|
55
|
+
recreate_domain
|
56
|
+
end
|
57
|
+
it "should pushing data to sdb domain" do
|
58
|
+
@rake[@task_name].invoke
|
59
|
+
Person.count.should == 1
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "db:collection:clear" do
|
64
|
+
before do
|
65
|
+
@task_name = "db:collection:clear"
|
66
|
+
recreate_domain
|
67
|
+
Person.create!(Person.valid_params)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should receive param with name \"name\"" do
|
71
|
+
@rake[@task_name].arg_names.should include(:name)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should receive param with name \"ccn\"" do
|
75
|
+
@rake[@task_name].arg_names.should include(:ccn)
|
76
|
+
end
|
77
|
+
it "should clear collection by name" do
|
78
|
+
@rake[@task_name].invoke("people")
|
79
|
+
Person.count.should == 0
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-simpledb-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ilia Ablamonov
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-01-
|
20
|
+
date: 2011-01-21 00:00:00 +03:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -126,6 +126,52 @@ dependencies:
|
|
126
126
|
name: activesupport
|
127
127
|
- !ruby/object:Gem::Dependency
|
128
128
|
version_requirements: &id008 !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - "="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
hash: -996198974
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
- 2
|
137
|
+
- 0
|
138
|
+
- prerails3
|
139
|
+
- 2
|
140
|
+
version: 0.2.0.prerails3.2
|
141
|
+
requirement: *id008
|
142
|
+
prerelease: false
|
143
|
+
type: :development
|
144
|
+
name: genspec
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
hash: 3
|
152
|
+
segments:
|
153
|
+
- 0
|
154
|
+
version: "0"
|
155
|
+
requirement: *id009
|
156
|
+
prerelease: false
|
157
|
+
type: :development
|
158
|
+
name: thor
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
hash: 3
|
166
|
+
segments:
|
167
|
+
- 0
|
168
|
+
version: "0"
|
169
|
+
requirement: *id010
|
170
|
+
prerelease: false
|
171
|
+
type: :development
|
172
|
+
name: rails
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
version_requirements: &id011 !ruby/object:Gem::Requirement
|
129
175
|
none: false
|
130
176
|
requirements:
|
131
177
|
- - ~>
|
@@ -136,12 +182,12 @@ dependencies:
|
|
136
182
|
- 3
|
137
183
|
- 0
|
138
184
|
version: 2.3.0
|
139
|
-
requirement: *
|
185
|
+
requirement: *id011
|
140
186
|
prerelease: false
|
141
187
|
type: :runtime
|
142
188
|
name: aws
|
143
189
|
- !ruby/object:Gem::Dependency
|
144
|
-
version_requirements: &
|
190
|
+
version_requirements: &id012 !ruby/object:Gem::Requirement
|
145
191
|
none: false
|
146
192
|
requirements:
|
147
193
|
- - ~>
|
@@ -152,12 +198,12 @@ dependencies:
|
|
152
198
|
- 0
|
153
199
|
- 3
|
154
200
|
version: 3.0.3
|
155
|
-
requirement: *
|
201
|
+
requirement: *id012
|
156
202
|
prerelease: false
|
157
203
|
type: :runtime
|
158
204
|
name: activerecord
|
159
205
|
- !ruby/object:Gem::Dependency
|
160
|
-
version_requirements: &
|
206
|
+
version_requirements: &id013 !ruby/object:Gem::Requirement
|
161
207
|
none: false
|
162
208
|
requirements:
|
163
209
|
- - ~>
|
@@ -168,12 +214,12 @@ dependencies:
|
|
168
214
|
- 0
|
169
215
|
- 3
|
170
216
|
version: 3.0.3
|
171
|
-
requirement: *
|
217
|
+
requirement: *id013
|
172
218
|
prerelease: false
|
173
219
|
type: :runtime
|
174
220
|
name: activesupport
|
175
221
|
- !ruby/object:Gem::Dependency
|
176
|
-
version_requirements: &
|
222
|
+
version_requirements: &id014 !ruby/object:Gem::Requirement
|
177
223
|
none: false
|
178
224
|
requirements:
|
179
225
|
- - ~>
|
@@ -184,10 +230,26 @@ dependencies:
|
|
184
230
|
- 1
|
185
231
|
- 1
|
186
232
|
version: 2.1.1
|
187
|
-
requirement: *
|
233
|
+
requirement: *id014
|
188
234
|
prerelease: false
|
189
235
|
type: :runtime
|
190
236
|
name: uuidtools
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
version_requirements: &id015 !ruby/object:Gem::Requirement
|
239
|
+
none: false
|
240
|
+
requirements:
|
241
|
+
- - ~>
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
hash: 1
|
244
|
+
segments:
|
245
|
+
- 3
|
246
|
+
- 0
|
247
|
+
- 3
|
248
|
+
version: 3.0.3
|
249
|
+
requirement: *id015
|
250
|
+
prerelease: false
|
251
|
+
type: :runtime
|
252
|
+
name: rails
|
191
253
|
description:
|
192
254
|
email: ilia@flamefork.ru
|
193
255
|
executables: []
|
@@ -198,20 +260,28 @@ extra_rdoc_files:
|
|
198
260
|
- LICENSE.txt
|
199
261
|
- README.md
|
200
262
|
files:
|
263
|
+
- Gemfile
|
264
|
+
- Gemfile.lock
|
201
265
|
- LICENSE.txt
|
202
266
|
- README.md
|
203
267
|
- activerecord-simpledb-adapter.gemspec
|
204
268
|
- lib/active_record/connection_adapters/simpledb_adapter.rb
|
205
269
|
- lib/activerecord-simpledb-adapter.rb
|
206
270
|
- lib/arel/visitors/simpledb.rb
|
271
|
+
- lib/generators/active_record/model/model_generator.rb
|
272
|
+
- lib/generators/active_record/model/templates/model.rb
|
207
273
|
- lib/tasks/simpledb.rake
|
208
274
|
- spec/active_record/connection_adapters/simpledb_adapter_spec.rb
|
209
275
|
- spec/active_record/core_actions_spec.rb
|
276
|
+
- spec/active_record/defaults_spec.rb
|
210
277
|
- spec/active_record/locking_spec.rb
|
211
278
|
- spec/active_record/record_attributes_spec.rb
|
212
279
|
- spec/active_record/validates_spec.rb
|
213
280
|
- spec/active_record/where_spec.rb
|
281
|
+
- spec/assets/db/seeds.rb
|
282
|
+
- spec/generators/model_spec.rb
|
214
283
|
- spec/spec_helper.rb
|
284
|
+
- spec/tasks/rake_spec.rb
|
215
285
|
has_rdoc: true
|
216
286
|
homepage: http://github.com/cloudcastle/activerecord-simpledb-adapter
|
217
287
|
licenses:
|
@@ -249,8 +319,12 @@ summary: ActiveRecord SimpleDB adapter
|
|
249
319
|
test_files:
|
250
320
|
- spec/active_record/connection_adapters/simpledb_adapter_spec.rb
|
251
321
|
- spec/active_record/core_actions_spec.rb
|
322
|
+
- spec/active_record/defaults_spec.rb
|
252
323
|
- spec/active_record/locking_spec.rb
|
253
324
|
- spec/active_record/record_attributes_spec.rb
|
254
325
|
- spec/active_record/validates_spec.rb
|
255
326
|
- spec/active_record/where_spec.rb
|
327
|
+
- spec/assets/db/seeds.rb
|
328
|
+
- spec/generators/model_spec.rb
|
256
329
|
- spec/spec_helper.rb
|
330
|
+
- spec/tasks/rake_spec.rb
|