mongify 1.3.2 → 1.4.1
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.
- checksums.yaml +5 -5
- data/.gitignore +3 -0
- data/CHANGELOG.md +34 -1
- data/CLAUDE.md +101 -0
- data/Gemfile +3 -3
- data/Gemfile.lock +123 -95
- data/README.rdoc +16 -8
- data/Rakefile +12 -1
- data/bin/dev-db +35 -0
- data/bin/test-setup +11 -0
- data/docker-compose.dev.yml +38 -0
- data/features/support/env.rb +1 -1
- data/lib/mongify/cli/command/worker.rb +1 -1
- data/lib/mongify/configuration.rb +1 -1
- data/lib/mongify/database/column.rb +7 -7
- data/lib/mongify/database/data_row.rb +3 -3
- data/lib/mongify/database/no_sql_connection.rb +51 -27
- data/lib/mongify/translation/sync.rb +1 -1
- data/lib/mongify/version.rb +1 -1
- data/lib/mongify.rb +1 -0
- data/mongify.gemspec +10 -11
- data/spec/mongify/cli/command/version_spec.rb +1 -1
- data/spec/mongify/database/base_connection_spec.rb +1 -1
- data/spec/mongify/database/no_sql_connection_spec.rb +62 -31
- data/spec/spec_helper.rb +8 -3
- data/spec/support/config_reader.rb +1 -1
- data/spec/support/database.example +1 -1
- data/spec/support/database_generator.rb +12 -12
- metadata +42 -54
|
@@ -43,9 +43,9 @@ module Mongify
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
# Updated respond_to to return true if it's a key the hash
|
|
46
|
-
def respond_to?(method)
|
|
47
|
-
return true if @hash.has_key?(method.gsub('=', ''))
|
|
48
|
-
super
|
|
46
|
+
def respond_to?(method, include_private = false)
|
|
47
|
+
return true if @hash.has_key?(method.to_s.gsub('=', ''))
|
|
48
|
+
super
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
# Added the ability to read and write attributes in the hash
|
|
@@ -25,8 +25,6 @@ module Mongify
|
|
|
25
25
|
# <em>You're also able to set attributes via the options</em>
|
|
26
26
|
#
|
|
27
27
|
class NoSqlConnection < Mongify::Database::BaseConnection
|
|
28
|
-
include Mongo
|
|
29
|
-
|
|
30
28
|
|
|
31
29
|
#Required fields for a no sql connection
|
|
32
30
|
REQUIRED_FIELDS = %w{host database}
|
|
@@ -61,14 +59,20 @@ module Mongify
|
|
|
61
59
|
!!@options['force']
|
|
62
60
|
end
|
|
63
61
|
|
|
64
|
-
# Sets up a connection to the database
|
|
62
|
+
# Sets up a connection to the database using Mongo::Client (2.x driver)
|
|
65
63
|
def setup_connection_adapter
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
hosts = ["#{host}:#{port || 27017}"]
|
|
65
|
+
client_options = { database: database }
|
|
66
|
+
|
|
67
|
+
if username && password
|
|
68
|
+
client_options[:user] = username
|
|
69
|
+
client_options[:password] = password
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
Mongo::Client.new(hosts, client_options)
|
|
69
73
|
end
|
|
70
74
|
|
|
71
|
-
# Returns a mongo connection
|
|
75
|
+
# Returns a mongo client connection
|
|
72
76
|
# NOTE: If forced? is true, the first time a connection is made, it will ask to drop the
|
|
73
77
|
# database before continuing
|
|
74
78
|
def connection
|
|
@@ -77,33 +81,46 @@ module Mongify
|
|
|
77
81
|
@connection
|
|
78
82
|
end
|
|
79
83
|
|
|
84
|
+
# Alias for connection to make code more readable with 2.x driver
|
|
85
|
+
alias_method :client, :connection
|
|
86
|
+
|
|
80
87
|
# Returns true or false depending if we have a connection to a mongo server
|
|
81
88
|
def has_connection?
|
|
82
|
-
|
|
89
|
+
# In mongo 2.x, we ping the server to check connectivity
|
|
90
|
+
begin
|
|
91
|
+
client.database.command(ping: 1)
|
|
92
|
+
true
|
|
93
|
+
rescue Mongo::Error => e
|
|
94
|
+
false
|
|
95
|
+
end
|
|
83
96
|
end
|
|
84
97
|
|
|
85
98
|
# Returns the database from the connection
|
|
86
99
|
def db
|
|
87
|
-
@db ||=
|
|
100
|
+
@db ||= client.database
|
|
88
101
|
end
|
|
89
102
|
|
|
90
103
|
# Returns a hash of all the rows from the database of a given collection
|
|
91
104
|
def select_rows(collection)
|
|
92
|
-
|
|
105
|
+
client[collection].find
|
|
93
106
|
end
|
|
94
107
|
|
|
95
108
|
def select_by_query(collection, query)
|
|
96
|
-
|
|
109
|
+
client[collection].find(query)
|
|
97
110
|
end
|
|
98
111
|
|
|
99
|
-
# Inserts into the collection a given row
|
|
100
|
-
def insert_into(
|
|
101
|
-
|
|
112
|
+
# Inserts into the collection a given row or array of rows
|
|
113
|
+
def insert_into(collection_name, row)
|
|
114
|
+
if row.is_a?(Array)
|
|
115
|
+
client[collection_name].insert_many(row)
|
|
116
|
+
else
|
|
117
|
+
client[collection_name].insert_one(row)
|
|
118
|
+
end
|
|
102
119
|
end
|
|
103
120
|
|
|
104
121
|
# Updates a collection item with a given ID with the given attributes
|
|
105
|
-
def update(
|
|
106
|
-
|
|
122
|
+
def update(collection_name, id, attributes)
|
|
123
|
+
client[collection_name].replace_one({"_id" => id}, attributes)
|
|
107
124
|
end
|
|
108
125
|
|
|
109
126
|
# Upserts into the collection a given row
|
|
@@ -112,8 +129,6 @@ module Mongify
|
|
|
112
129
|
# The reason is that it detects duplicates using _id
|
|
113
130
|
# but we should detect it using pre_mongified_id instead
|
|
114
131
|
# because in the case of sync, same rows are identified by their original sql ids
|
|
115
|
-
#
|
|
116
|
-
# db[collection_name].save(row)
|
|
117
132
|
|
|
118
133
|
if row.has_key?(:pre_mongified_id) || row.has_key?('pre_mongified_id')
|
|
119
134
|
id = row[:pre_mongified_id] || row['pre_mongified_id']
|
|
@@ -124,25 +139,31 @@ module Mongify
|
|
|
124
139
|
insert_into(collection_name, row)
|
|
125
140
|
end
|
|
126
141
|
else
|
|
127
|
-
# no pre_mongified_id,
|
|
128
|
-
|
|
142
|
+
# no pre_mongified_id, use replace_one with upsert option
|
|
143
|
+
if row[:_id] || row["_id"]
|
|
144
|
+
id = row[:_id] || row["_id"]
|
|
145
|
+
client[collection_name].replace_one({"_id" => id}, row, upsert: true)
|
|
146
|
+
else
|
|
147
|
+
insert_into(collection_name, row)
|
|
148
|
+
end
|
|
129
149
|
end
|
|
130
150
|
end
|
|
131
151
|
|
|
132
152
|
# Finds one item from a collection with the given query
|
|
133
153
|
def find_one(collection_name, query)
|
|
134
|
-
|
|
154
|
+
client[collection_name].find(query).first
|
|
135
155
|
end
|
|
136
156
|
|
|
137
157
|
# Returns a row of a item from a given collection with a given pre_mongified_id
|
|
138
|
-
def get_id_using_pre_mongified_id(
|
|
139
|
-
|
|
158
|
+
def get_id_using_pre_mongified_id(collection_name, pre_mongified_id)
|
|
159
|
+
doc = client[collection_name].find('pre_mongified_id' => pre_mongified_id).first
|
|
160
|
+
doc ? doc['_id'] : nil
|
|
140
161
|
end
|
|
141
162
|
|
|
142
163
|
# Removes pre_mongified_id from all records in a given collection
|
|
143
164
|
def remove_pre_mongified_ids(collection_name)
|
|
144
165
|
drop_mongified_index(collection_name)
|
|
145
|
-
|
|
166
|
+
client[collection_name].update_many({}, { '$unset' => { 'pre_mongified_id' => 1} })
|
|
146
167
|
end
|
|
147
168
|
|
|
148
169
|
# Removes pre_mongified_id from collection
|
|
@@ -150,13 +171,16 @@ module Mongify
|
|
|
150
171
|
# @return True if successful
|
|
151
172
|
# @raise MongoDBError if index isn't found
|
|
152
173
|
def drop_mongified_index(collection_name)
|
|
153
|
-
|
|
174
|
+
index_names = client[collection_name].indexes.collect { |idx| idx['name'] }
|
|
175
|
+
if index_names.include?("pre_mongified_id_1")
|
|
176
|
+
client[collection_name].indexes.drop_one('pre_mongified_id_1')
|
|
177
|
+
end
|
|
154
178
|
end
|
|
155
179
|
|
|
156
180
|
# Creates a pre_mongified_id index to ensure
|
|
157
181
|
# speedy lookup for collections via the pre_mongified_id
|
|
158
182
|
def create_pre_mongified_id_index(collection_name)
|
|
159
|
-
|
|
183
|
+
client[collection_name].indexes.create_one({ 'pre_mongified_id' => 1 })
|
|
160
184
|
end
|
|
161
185
|
|
|
162
186
|
# Asks user permission to drop the database
|
|
@@ -173,7 +197,7 @@ module Mongify
|
|
|
173
197
|
|
|
174
198
|
# Drops the mongodb database
|
|
175
199
|
def drop_database
|
|
176
|
-
|
|
200
|
+
client.database.drop
|
|
177
201
|
end
|
|
178
202
|
|
|
179
203
|
|
|
@@ -10,7 +10,7 @@ module Mongify
|
|
|
10
10
|
DRAFT_KEY = "__mongify_sync_draft__"
|
|
11
11
|
SYNC_HELPER_TABLE = "__mongify_sync_helper__"
|
|
12
12
|
|
|
13
|
-
class SyncHelperMigrator < ActiveRecord::Migration
|
|
13
|
+
class SyncHelperMigrator < ActiveRecord::Migration[5.0]
|
|
14
14
|
def up
|
|
15
15
|
create_table SYNC_HELPER_TABLE, :id => false do |t|
|
|
16
16
|
t.string :table_name
|
data/lib/mongify/version.rb
CHANGED
data/lib/mongify.rb
CHANGED
data/mongify.gemspec
CHANGED
|
@@ -10,24 +10,23 @@ Gem::Specification.new do |s|
|
|
|
10
10
|
s.homepage = "http://mongify.com"
|
|
11
11
|
s.summary = %q{Translate your SQL data to MongoDB with ease}
|
|
12
12
|
s.description = %q{Mongify allows you to map your sql data into a mongodb document database with a simple DSL.}
|
|
13
|
-
s.required_ruby_version = ">=
|
|
13
|
+
s.required_ruby_version = ">= 3.0"
|
|
14
14
|
|
|
15
|
-
s.add_runtime_dependency('activerecord', ">=
|
|
16
|
-
s.add_runtime_dependency('activesupport', ">=
|
|
17
|
-
s.add_runtime_dependency('mongo', "
|
|
18
|
-
s.add_runtime_dependency('
|
|
19
|
-
s.add_runtime_dependency('
|
|
20
|
-
s.add_runtime_dependency('highline', '= 1.7.8')
|
|
15
|
+
s.add_runtime_dependency('activerecord', ">= 7.1.5.2", "< 8.0")
|
|
16
|
+
s.add_runtime_dependency('activesupport', ">= 7.1.5.2", "< 8.0")
|
|
17
|
+
s.add_runtime_dependency('mongo', "~> 2.19")
|
|
18
|
+
s.add_runtime_dependency('highline', '>= 1.7.8')
|
|
19
|
+
s.add_runtime_dependency('abbrev') # Required for Ruby 3.4+ (removed from stdlib)
|
|
21
20
|
|
|
22
21
|
|
|
23
|
-
s.add_development_dependency('rspec', '~>
|
|
22
|
+
s.add_development_dependency('rspec', '~> 3.0')
|
|
24
23
|
s.add_development_dependency('rspec-collection_matchers', '~> 1.0')
|
|
25
|
-
s.add_development_dependency('cucumber', '>= 0
|
|
24
|
+
s.add_development_dependency('cucumber', '>= 9.0')
|
|
26
25
|
s.add_development_dependency('mocha', '>= 0.9.8')
|
|
27
|
-
s.add_development_dependency('yard', '
|
|
26
|
+
s.add_development_dependency('yard', '~> 0.9.11')
|
|
28
27
|
s.add_development_dependency('sqlite3', '>= 1.3')
|
|
29
28
|
s.add_development_dependency('pg', '>= 0.17')
|
|
30
|
-
s.add_development_dependency('mysql2', '>= 0.4')
|
|
29
|
+
s.add_development_dependency('mysql2', '>= 0.4.10')
|
|
31
30
|
s.add_development_dependency('watchr', '>= 0.6')
|
|
32
31
|
s.add_development_dependency('rake')
|
|
33
32
|
s.add_development_dependency('jazz_fingers')
|
|
@@ -35,7 +35,7 @@ describe Mongify::Database::BaseConnection do
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
it "should raise error on setting unknown variable setting" do
|
|
38
|
-
lambda{@base_connection.connection = "localhost"}.should raise_error
|
|
38
|
+
lambda{@base_connection.connection = "localhost"}.should raise_error(NoMethodError)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it "should respond to available settings" do
|
|
@@ -48,47 +48,63 @@ describe Mongify::Database::NoSqlConnection do
|
|
|
48
48
|
|
|
49
49
|
context "connection" do
|
|
50
50
|
before(:each) do
|
|
51
|
-
@
|
|
52
|
-
Mongo::
|
|
51
|
+
@mock_client = double('Mongo::Client')
|
|
52
|
+
@mock_database = double('Mongo::Database')
|
|
53
|
+
@mock_client.stub(:database).and_return(@mock_database)
|
|
54
|
+
@mock_database.stub(:command).and_return(double)
|
|
55
|
+
Mongo::Client.stub(:new).and_return(@mock_client)
|
|
53
56
|
end
|
|
54
57
|
|
|
55
58
|
it "should only create a connection once" do
|
|
56
|
-
Mongo::
|
|
59
|
+
Mongo::Client.should_receive(:new).once
|
|
60
|
+
@mongodb_connection.host 'localhost'
|
|
61
|
+
@mongodb_connection.database 'test'
|
|
57
62
|
@mongodb_connection.connection
|
|
58
63
|
@mongodb_connection.connection
|
|
59
64
|
end
|
|
60
65
|
|
|
61
|
-
it "should
|
|
62
|
-
@
|
|
66
|
+
it "should include credentials in client options if username && password is present" do
|
|
67
|
+
@mongodb_connection.host 'localhost'
|
|
68
|
+
@mongodb_connection.database 'test'
|
|
63
69
|
@mongodb_connection.username "bob"
|
|
64
70
|
@mongodb_connection.password "secret"
|
|
71
|
+
Mongo::Client.should_receive(:new).with(
|
|
72
|
+
["localhost:27017"],
|
|
73
|
+
hash_including(user: "bob", password: "secret", database: "test")
|
|
74
|
+
).and_return(@mock_client)
|
|
65
75
|
@mongodb_connection.connection
|
|
66
76
|
end
|
|
67
|
-
|
|
68
77
|
end
|
|
69
78
|
|
|
70
79
|
|
|
71
80
|
context "database action:" do
|
|
72
81
|
before(:each) do
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
82
|
+
@mongodb_connection.host 'localhost'
|
|
83
|
+
@mongodb_connection.database 'test'
|
|
84
|
+
@collection = double('collection')
|
|
85
|
+
@mock_client = double('Mongo::Client')
|
|
86
|
+
@mock_client.stub(:[]).with('users').and_return(@collection)
|
|
87
|
+
@mongodb_connection.stub(:client).and_return(@mock_client)
|
|
77
88
|
end
|
|
89
|
+
|
|
78
90
|
context "insert_into" do
|
|
79
91
|
it "should insert into a table using the mongo driver" do
|
|
80
|
-
@collection.should_receive(:
|
|
92
|
+
@collection.should_receive(:insert_one).with({'first_name' => 'bob'})
|
|
81
93
|
@mongodb_connection.insert_into('users', {'first_name' => 'bob'})
|
|
82
94
|
end
|
|
83
95
|
end
|
|
84
96
|
|
|
85
97
|
context "get_id_using_pre_mongified_id" do
|
|
86
98
|
it "should return new id" do
|
|
87
|
-
|
|
99
|
+
cursor = double('cursor')
|
|
100
|
+
cursor.stub(:first).and_return({'_id' => '123'})
|
|
101
|
+
@collection.should_receive(:find).with({"pre_mongified_id"=>1}).and_return(cursor)
|
|
88
102
|
@mongodb_connection.get_id_using_pre_mongified_id('users', 1).should == '123'
|
|
89
103
|
end
|
|
90
104
|
it "should return nil if nothing is found" do
|
|
91
|
-
|
|
105
|
+
cursor = double('cursor')
|
|
106
|
+
cursor.stub(:first).and_return(nil)
|
|
107
|
+
@collection.should_receive(:find).with({"pre_mongified_id"=>1}).and_return(cursor)
|
|
92
108
|
@mongodb_connection.get_id_using_pre_mongified_id('users', 1).should == nil
|
|
93
109
|
end
|
|
94
110
|
end
|
|
@@ -111,7 +127,7 @@ describe Mongify::Database::NoSqlConnection do
|
|
|
111
127
|
context "update" do
|
|
112
128
|
it "should update the record" do
|
|
113
129
|
attributes = {'post_id' => 123}
|
|
114
|
-
@collection.should_receive(:
|
|
130
|
+
@collection.should_receive(:replace_one).with({"_id" => 1}, attributes)
|
|
115
131
|
@mongodb_connection.update('users', 1, attributes)
|
|
116
132
|
end
|
|
117
133
|
end
|
|
@@ -135,38 +151,50 @@ describe Mongify::Database::NoSqlConnection do
|
|
|
135
151
|
@mongodb_connection.upsert('users', attributes)
|
|
136
152
|
end
|
|
137
153
|
|
|
138
|
-
it "should
|
|
154
|
+
it "should use replace_one with upsert if _id is present but no pre_mongified_id" do
|
|
155
|
+
attributes = {'_id' => 'abc123', 'post_id' => 123}
|
|
156
|
+
@collection.should_receive(:replace_one).with({"_id" => 'abc123'}, attributes, upsert: true)
|
|
157
|
+
@mongodb_connection.upsert('users', attributes)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
it "should insert if no _id and no pre_mongified_id" do
|
|
139
161
|
attributes = {'post_id' => 123}
|
|
140
|
-
@
|
|
162
|
+
@mongodb_connection.should_receive(:insert_into).with('users', attributes)
|
|
141
163
|
@mongodb_connection.upsert('users', attributes)
|
|
142
164
|
end
|
|
143
165
|
end
|
|
144
166
|
|
|
145
167
|
context "find_one" do
|
|
146
|
-
it "should call
|
|
147
|
-
query= {'pre_mongified_id' => 1}
|
|
148
|
-
|
|
168
|
+
it "should call find and return first result" do
|
|
169
|
+
query = {'pre_mongified_id' => 1}
|
|
170
|
+
cursor = double('cursor')
|
|
171
|
+
cursor.stub(:first).and_return({'_id' => '123'})
|
|
172
|
+
@collection.should_receive(:find).with(query).and_return(cursor)
|
|
149
173
|
@mongodb_connection.find_one('users', query)
|
|
150
174
|
end
|
|
151
175
|
end
|
|
152
176
|
|
|
153
177
|
it "should create index for pre_mongified_id" do
|
|
154
|
-
|
|
178
|
+
indexes = double('indexes')
|
|
179
|
+
@collection.stub(:indexes).and_return(indexes)
|
|
180
|
+
indexes.should_receive(:create_one).with({ 'pre_mongified_id' => 1 }).and_return(true)
|
|
155
181
|
@mongodb_connection.create_pre_mongified_id_index('users')
|
|
156
182
|
end
|
|
157
183
|
|
|
158
184
|
context "remove_pre_mongified_ids" do
|
|
159
185
|
before(:each) do
|
|
160
|
-
@
|
|
186
|
+
@indexes = double('indexes')
|
|
187
|
+
@indexes.stub(:collect).and_return(['pre_mongified_id_1'])
|
|
188
|
+
@collection.stub(:indexes).and_return(@indexes)
|
|
161
189
|
end
|
|
162
|
-
it "should call
|
|
163
|
-
@collection.should_receive(:
|
|
164
|
-
@
|
|
190
|
+
it "should call update_many with unset" do
|
|
191
|
+
@collection.should_receive(:update_many).with({},{'$unset' => {'pre_mongified_id' => 1}})
|
|
192
|
+
@indexes.stub(:drop_one)
|
|
165
193
|
@mongodb_connection.remove_pre_mongified_ids('users')
|
|
166
194
|
end
|
|
167
195
|
it "should drop the index" do
|
|
168
|
-
@
|
|
169
|
-
@collection.stub(:
|
|
196
|
+
@indexes.should_receive(:drop_one).with('pre_mongified_id_1')
|
|
197
|
+
@collection.stub(:update_many)
|
|
170
198
|
@mongodb_connection.remove_pre_mongified_ids('users')
|
|
171
199
|
end
|
|
172
200
|
end
|
|
@@ -174,8 +202,12 @@ describe Mongify::Database::NoSqlConnection do
|
|
|
174
202
|
|
|
175
203
|
context "force" do
|
|
176
204
|
before(:each) do
|
|
177
|
-
@
|
|
178
|
-
Mongo::
|
|
205
|
+
@mock_client = double('Mongo::Client')
|
|
206
|
+
@mock_database = double('Mongo::Database')
|
|
207
|
+
@mock_client.stub(:database).and_return(@mock_database)
|
|
208
|
+
@mock_database.stub(:command).and_return(double)
|
|
209
|
+
@mock_database.stub(:drop).and_return(true)
|
|
210
|
+
Mongo::Client.stub(:new).and_return(@mock_client)
|
|
179
211
|
@mongodb_connection = Mongify::Database::NoSqlConnection.new(:host => 'localhost', :database => 'blue', :force => true)
|
|
180
212
|
Mongify::UI.stub(:ask).and_return(true)
|
|
181
213
|
end
|
|
@@ -187,7 +219,7 @@ describe Mongify::Database::NoSqlConnection do
|
|
|
187
219
|
end
|
|
188
220
|
|
|
189
221
|
it "should drop database" do
|
|
190
|
-
@
|
|
222
|
+
@mock_database.should_receive(:drop).and_return(true)
|
|
191
223
|
@mongodb_connection.send(:drop_database)
|
|
192
224
|
end
|
|
193
225
|
|
|
@@ -221,9 +253,8 @@ describe Mongify::Database::NoSqlConnection do
|
|
|
221
253
|
end
|
|
222
254
|
|
|
223
255
|
it "should return a db" do
|
|
224
|
-
@mongodb_connection.db.should be_a
|
|
256
|
+
@mongodb_connection.db.should be_a Mongo::Database
|
|
225
257
|
end
|
|
226
258
|
end
|
|
227
259
|
|
|
228
260
|
end
|
|
229
|
-
|
data/spec/spec_helper.rb
CHANGED
|
@@ -22,9 +22,14 @@ Mongify.root = File.dirname(File.dirname(__FILE__))
|
|
|
22
22
|
|
|
23
23
|
::DATABASE_PRINT = File.read(File.dirname(File.expand_path(__FILE__)) + '/support/database_output.txt')
|
|
24
24
|
|
|
25
|
-
#
|
|
26
|
-
RSpec.configure do |
|
|
27
|
-
|
|
25
|
+
# Enable legacy :should syntax for backwards compatibility
|
|
26
|
+
RSpec.configure do |config|
|
|
27
|
+
config.expect_with :rspec do |c|
|
|
28
|
+
c.syntax = [:should, :expect]
|
|
29
|
+
end
|
|
30
|
+
config.mock_with :rspec do |c|
|
|
31
|
+
c.syntax = [:should, :expect]
|
|
32
|
+
end
|
|
28
33
|
end
|
|
29
34
|
# mute the deprecation message from I18n
|
|
30
35
|
I18n.enforce_available_locales = false
|
|
@@ -31,7 +31,7 @@ class DatabaseGenerator
|
|
|
31
31
|
|
|
32
32
|
# Creates a new mysql database (and deletes the old one)
|
|
33
33
|
def self.sqlite(include_data=true)
|
|
34
|
-
File.delete(sqlite_connection.database) if File.
|
|
34
|
+
File.delete(sqlite_connection.database) if File.exist?(sqlite_connection.database)
|
|
35
35
|
|
|
36
36
|
conn = sqlite_connection.connection
|
|
37
37
|
|
|
@@ -91,17 +91,17 @@ class DatabaseGenerator
|
|
|
91
91
|
{:first_name => 'Bob', :last_name => 'Smith'},
|
|
92
92
|
{:first_name => 'Joe', :last_name => 'Franklin'}
|
|
93
93
|
].each do |values|
|
|
94
|
-
conn.insert("INSERT INTO users (first_name, last_name, created_at, updated_at) VALUES ('#{values[:first_name]}', '#{values[:last_name]}', '#{Time.now.
|
|
94
|
+
conn.insert("INSERT INTO users (first_name, last_name, created_at, updated_at) VALUES ('#{values[:first_name]}', '#{values[:last_name]}', '#{Time.now.to_fs(:db)}', '#{Time.now.to_fs(:db)}')")
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
#Posts
|
|
98
98
|
[
|
|
99
|
-
{:title => 'First Post', :owner_id => 1, :body => 'First Post Body', :published_at => (Time.now - 2).
|
|
100
|
-
{:title => 'Second Post', :owner_id => 1, :body => 'Second Post Body', :published_at => (Time.now - 1).
|
|
101
|
-
{:title => 'Third Post', :owner_id => 2, :body => 'Third Post Body', :published_at => (Time.now).
|
|
99
|
+
{:title => 'First Post', :owner_id => 1, :body => 'First Post Body', :published_at => (Time.now - 2).to_fs(:db)},
|
|
100
|
+
{:title => 'Second Post', :owner_id => 1, :body => 'Second Post Body', :published_at => (Time.now - 1).to_fs(:db)},
|
|
101
|
+
{:title => 'Third Post', :owner_id => 2, :body => 'Third Post Body', :published_at => (Time.now).to_fs(:db)},
|
|
102
102
|
].each do |v|
|
|
103
103
|
conn.insert("INSERT INTO posts (title, owner_id, body, published_at, created_at, updated_at)
|
|
104
|
-
VALUES ('#{v[:title]}', #{v[:owner_id]}, '#{v[:body]}', '#{v[:published_at]}', '#{Time.now.
|
|
104
|
+
VALUES ('#{v[:title]}', #{v[:owner_id]}, '#{v[:body]}', '#{v[:published_at]}', '#{Time.now.to_fs(:db)}', '#{Time.now.to_fs(:db)}')")
|
|
105
105
|
end
|
|
106
106
|
|
|
107
107
|
#Comments
|
|
@@ -111,7 +111,7 @@ class DatabaseGenerator
|
|
|
111
111
|
{:post_id => 2, :user_id => 2, :body => 'Third Comment Body'},
|
|
112
112
|
].each do |v|
|
|
113
113
|
conn.insert("INSERT INTO comments (body, post_id, user_id, created_at, updated_at)
|
|
114
|
-
VALUES ('#{v[:body]}', #{v[:post_id]}, #{v[:user_id]}, '#{Time.now.
|
|
114
|
+
VALUES ('#{v[:body]}', #{v[:post_id]}, #{v[:user_id]}, '#{Time.now.to_fs(:db)}', '#{Time.now.to_fs(:db)}')")
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
#Preferences
|
|
@@ -121,7 +121,7 @@ class DatabaseGenerator
|
|
|
121
121
|
{:user_id => 3, :notify_by_email => false},
|
|
122
122
|
].each_with_index do |v, idx|
|
|
123
123
|
conn.insert("INSERT INTO preferences (id, user_id, notify_by_email, created_at, updated_at)
|
|
124
|
-
VALUES ('p#{idx+1}',#{v[:user_id]}, '#{v[:notify_by_email]}', '#{Time.now.
|
|
124
|
+
VALUES ('p#{idx+1}',#{v[:user_id]}, '#{v[:notify_by_email]}', '#{Time.now.to_fs(:db)}', '#{Time.now.to_fs(:db)}')")
|
|
125
125
|
end
|
|
126
126
|
|
|
127
127
|
#Notes
|
|
@@ -132,7 +132,7 @@ class DatabaseGenerator
|
|
|
132
132
|
{:user_id => 3, :body => 'note 4', :notable_id => 2, :notable_type => 'User'},
|
|
133
133
|
].each do |v|
|
|
134
134
|
conn.insert("INSERT INTO notes (user_id, body, notable_id, notable_type, created_at, updated_at)
|
|
135
|
-
VALUES (#{v[:user_id]}, '#{v[:body]}', #{v[:notable_id]}, '#{v[:notable_type]}', '#{Time.now.
|
|
135
|
+
VALUES (#{v[:user_id]}, '#{v[:body]}', #{v[:notable_id]}, '#{v[:notable_type]}', '#{Time.now.to_fs(:db)}', '#{Time.now.to_fs(:db)}')")
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
#Teams
|
|
@@ -142,7 +142,7 @@ class DatabaseGenerator
|
|
|
142
142
|
{:name => 'Copenhagen Crushers', :phone => '+1112223334'}
|
|
143
143
|
].each do |v|
|
|
144
144
|
conn.insert("INSERT INTO teams (name, phone, created_at, updated_at)
|
|
145
|
-
VALUES ('#{v[:name]}', '#{v[:phone]}', '#{Time.now.
|
|
145
|
+
VALUES ('#{v[:name]}', '#{v[:phone]}', '#{Time.now.to_fs(:db)}', '#{Time.now.to_fs(:db)}')")
|
|
146
146
|
end
|
|
147
147
|
|
|
148
148
|
#Coaches
|
|
@@ -152,7 +152,7 @@ class DatabaseGenerator
|
|
|
152
152
|
{:team_id => 3, :first_name => 'Carl', :last_name => 'Cooper'}
|
|
153
153
|
].each do |v|
|
|
154
154
|
conn.insert("INSERT INTO coaches (team_id, first_name, last_name, created_at, updated_at)
|
|
155
|
-
VALUES (#{v[:team_id]}, '#{v[:first_name]}', '#{v[:last_name]}', '#{Time.now.
|
|
155
|
+
VALUES (#{v[:team_id]}, '#{v[:first_name]}', '#{v[:last_name]}', '#{Time.now.to_fs(:db)}', '#{Time.now.to_fs(:db)}')")
|
|
156
156
|
end
|
|
157
157
|
|
|
158
158
|
end
|
|
@@ -162,7 +162,7 @@ class DatabaseGenerator
|
|
|
162
162
|
|
|
163
163
|
# Drops the database in mongo
|
|
164
164
|
def self.clear_mongodb
|
|
165
|
-
mongo_connection.
|
|
165
|
+
mongo_connection.db.drop
|
|
166
166
|
end
|
|
167
167
|
|
|
168
168
|
# Returns a mongo connection (based on the database.yml)
|