sequel-rails 0.6.1 → 0.7.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.
@@ -36,8 +36,16 @@ describe SequelRails::Migrations do
36
36
  described_class.pending_migrations?.should == false
37
37
  end
38
38
 
39
- context "when db/migrate directory exists" do
40
- before { FileUtils.mkdir_p path }
39
+ it "returns false if db/migrate directory exists, but is empty" do
40
+ FileUtils.mkdir_p path
41
+ described_class.pending_migrations?.should == false
42
+ end
43
+
44
+ context "when db/migrate directory exists and contains migrations" do
45
+ before do
46
+ FileUtils.mkdir_p path
47
+ FileUtils.touch(File.join(path, 'test_migration.rb'))
48
+ end
41
49
 
42
50
  it "returns true if any pending migration" do
43
51
  ::Sequel::Migrator.should_receive(:is_current?).with(
@@ -0,0 +1,64 @@
1
+ require "spec_helper"
2
+
3
+ describe SequelRails::Storage::Mysql, :mysql do
4
+ let(:username) { "username" }
5
+ let(:host) { "host" }
6
+ let(:port) { 1234 }
7
+ let(:password) { "password" }
8
+ let(:charset) { "charset" }
9
+ let(:collation) { "collation" }
10
+ let(:database) { "database" }
11
+ let(:config) do
12
+ {
13
+ "adapter" => "postgres",
14
+ "username" => username,
15
+ "password" => password,
16
+ "host" => host,
17
+ "port" => port,
18
+ "database" => database,
19
+ "charset" => charset,
20
+ "collation" => collation,
21
+ }
22
+ end
23
+ subject { described_class.new config }
24
+
25
+ describe "#_create" do
26
+ context "with all possible options" do
27
+ it "uses the mysql command" do
28
+ subject.should_receive(:`).with(
29
+ "mysql --user\\=#{username} --password\\=#{password} --host\\=#{host} --port\\=#{port} --execute\\=CREATE\\ DATABASE\\ IF\\ NOT\\ EXISTS\\ \\`#{database}\\`\\ DEFAULT\\ CHARACTER\\ SET\\ #{charset}\\ DEFAULT\\ COLLATE\\ #{collation}"
30
+ )
31
+ subject._create
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "#_drop" do
37
+ it "uses the mysql command" do
38
+ subject.should_receive(:`).with(
39
+ "mysql --user\\=#{username} --password\\=#{password} --host\\=#{host} --port\\=#{port} --execute\\=DROP\\ DATABASE\\ IF\\ EXISTS\\ \\`#{database}\\`"
40
+ )
41
+ subject._drop
42
+ end
43
+ end
44
+
45
+ describe "#_dump" do
46
+ let(:dump_file_name) { "dump.sql" }
47
+ it "uses the mysqldump command" do
48
+ subject.should_receive(:`).with(
49
+ "mysqldump --user\\=#{username} --password\\=#{password} --host\\=#{host} --port\\=#{port} --no-data --result-file\\=#{dump_file_name} #{database}"
50
+ )
51
+ subject._dump dump_file_name
52
+ end
53
+ end
54
+
55
+ describe "#_load" do
56
+ let(:dump_file_name) { "dump.sql" }
57
+ it "uses the mysql command" do
58
+ subject.should_receive(:`).with(
59
+ "mysql --user\\=username --password\\=password --host\\=host --port\\=1234 --database\\=database --execute\\=SET\\ FOREIGN_KEY_CHECKS\\ \\=\\ 0\\;\\ SOURCE\\ dump.sql\\;\\ SET\\ FOREIGN_KEY_CHECKS\\ \\=\\ 1"
60
+ )
61
+ subject._load dump_file_name
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,121 @@
1
+ require "spec_helper"
2
+
3
+ describe SequelRails::Storage::Postgres, :postgres do
4
+ let(:username) { "username" }
5
+ let(:host) { "host" }
6
+ let(:port) { 1234 }
7
+ let(:password) { "password" }
8
+ let(:maintenance_db){ "maintenance_db" }
9
+ let(:encoding) { "encoding" }
10
+ let(:locale) { "locale" }
11
+ let(:collation) { "collation" }
12
+ let(:ctype) { "ctype" }
13
+ let(:template) { "template" }
14
+ let(:tablespace) { "tablespace" }
15
+ let(:owner) { "owner" }
16
+ let(:database) { "database" }
17
+ let(:config) do
18
+ {
19
+ "adapter" => "postgres",
20
+ "username" => username,
21
+ "password" => password,
22
+ "host" => host,
23
+ "port" => port,
24
+ "maintenance_db" => maintenance_db,
25
+ "encoding" => encoding,
26
+ "locale" => locale,
27
+ "collation" => collation,
28
+ "ctype" => ctype,
29
+ "template" => template,
30
+ "tablespace" => tablespace,
31
+ "owner" => owner,
32
+ "database" => database,
33
+ }
34
+ end
35
+
36
+ subject { described_class.new config }
37
+
38
+ describe "#_create" do
39
+ context "with all possible options" do
40
+ it "uses the createdb command" do
41
+ subject.should_receive(:`).with(
42
+ "createdb --username\\=#{username} --host\\=#{host} --port\\=#{port} --maintenance-db\\=#{maintenance_db} --encoding\\=#{encoding} --locale\\=#{locale} --lc-collate\\=#{collation} --lc-ctype\\=#{ctype} --template\\=#{template} --tablespace\\=#{tablespace} --owner\\=#{owner} #{database}"
43
+ )
44
+ subject._create
45
+ end
46
+ end
47
+
48
+ context "with only a subset of possible options" do
49
+ let(:maintenance_db) { "" }
50
+ let(:locale) { "" }
51
+ it "uses the createdb command" do
52
+ subject.should_receive(:`).with(
53
+ "createdb --username\\=#{username} --host\\=#{host} --port\\=#{port} --encoding\\=#{encoding} --lc-collate\\=#{collation} --lc-ctype\\=#{ctype} --template\\=#{template} --tablespace\\=#{tablespace} --owner\\=#{owner} #{database}"
54
+ )
55
+ subject._create
56
+ end
57
+ end
58
+
59
+ it "sets and remove the password in environment variable PGPASSWORD" do
60
+ ENV["PGPASSWORD"].should be_nil
61
+ subject.should_receive(:`) do |_|
62
+ ENV["PGPASSWORD"].should == password
63
+ end
64
+ subject._create
65
+ ENV["PGPASSWORD"].should be_nil
66
+ end
67
+ end
68
+
69
+ describe "#_drop" do
70
+ it "uses the dropdb command" do
71
+ subject.should_receive(:`).with(
72
+ "dropdb --username\\=#{username} --host\\=#{host} --port\\=#{port} #{database}"
73
+ )
74
+ subject._drop
75
+ end
76
+ it "sets and remove the password in environment variable PGPASSWORD" do
77
+ ENV["PGPASSWORD"].should be_nil
78
+ subject.should_receive(:`) do |_|
79
+ ENV["PGPASSWORD"].should == password
80
+ end
81
+ subject._drop
82
+ ENV["PGPASSWORD"].should be_nil
83
+ end
84
+ end
85
+
86
+ describe "#_dump" do
87
+ let(:dump_file_name) { "dump.sql" }
88
+ it "uses the pg_dump command" do
89
+ subject.should_receive(:`).with(
90
+ "pg_dump --username\\=#{username} --host\\=#{host} --port\\=#{port} -i -s -x -O --file\\=#{dump_file_name} #{database}"
91
+ )
92
+ subject._dump dump_file_name
93
+ end
94
+ it "sets and remove the password in environment variable PGPASSWORD" do
95
+ ENV["PGPASSWORD"].should be_nil
96
+ subject.should_receive(:`) do |_|
97
+ ENV["PGPASSWORD"].should == password
98
+ end
99
+ subject._dump dump_file_name
100
+ ENV["PGPASSWORD"].should be_nil
101
+ end
102
+ end
103
+
104
+ describe "#_load" do
105
+ let(:dump_file_name) { "dump.sql" }
106
+ it "uses the psql command" do
107
+ subject.should_receive(:`).with(
108
+ "psql --username\\=#{username} --host\\=#{host} --port\\=#{port} --file\\=#{dump_file_name} #{database}"
109
+ )
110
+ subject._load dump_file_name
111
+ end
112
+ it "sets and remove the password in environment variable PGPASSWORD" do
113
+ ENV["PGPASSWORD"].should be_nil
114
+ subject.should_receive(:`) do |_|
115
+ ENV["PGPASSWORD"].should == password
116
+ end
117
+ subject._load dump_file_name
118
+ ENV["PGPASSWORD"].should be_nil
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,88 @@
1
+ require "spec_helper"
2
+
3
+ describe SequelRails::Storage::Sqlite, :sqlite do
4
+ let(:config) do
5
+ {
6
+ "adapter" => "sqlite3",
7
+ "database" => database,
8
+ }
9
+ end
10
+ subject { described_class.new config }
11
+
12
+ context "when database is not in memory" do
13
+ let(:database) { "test_database.sqlite" }
14
+ let(:database_path) { "#{Combustion::Application.root}/#{database}" }
15
+
16
+ describe "#_create" do
17
+ it "defer to Sequel" do
18
+ path = mock :path
19
+ subject.stub(:path).and_return path
20
+ ::Sequel.should_receive(:connect).with("adapter"=>"sqlite3", "database"=>path)
21
+ subject._create
22
+ end
23
+ end
24
+
25
+ describe "#_drop" do
26
+ it "delete the database file" do
27
+ path = mock :path, :file? => true
28
+ subject.stub(:path).and_return path
29
+ path.should_receive :unlink
30
+ subject._drop
31
+ end
32
+ end
33
+
34
+ describe "#_dump" do
35
+ let(:dump_file_name) { "dump.sql" }
36
+ it "uses the sqlite3 command" do
37
+ subject.should_receive(:`).with(
38
+ "sqlite3 #{database_path} .schema > #{dump_file_name}"
39
+ )
40
+ subject._dump dump_file_name
41
+ end
42
+ end
43
+
44
+ describe "#_load" do
45
+ let(:dump_file_name) { "dump.sql" }
46
+ it "uses the sqlite3 command" do
47
+ subject.should_receive(:`).with(
48
+ "sqlite3 #{database_path} < #{dump_file_name}"
49
+ )
50
+ subject._load dump_file_name
51
+ end
52
+ end
53
+ end
54
+
55
+ context "when database is in memory" do
56
+ let(:database) { ":memory:" }
57
+
58
+ describe "#_create" do
59
+ it "don't do anything" do
60
+ ::Sequel.should_not_receive(:connect)
61
+ subject._create
62
+ end
63
+ end
64
+
65
+ describe "#_drop" do
66
+ it "do not try to delete the database file" do
67
+ path = mock :path, :file? => true
68
+ subject.stub(:path).and_return path
69
+ path.should_not_receive :unlink
70
+ subject._drop
71
+ end
72
+ end
73
+
74
+ describe "#_dump" do
75
+ it "do not dump anything" do
76
+ subject.should_not_receive(:`)
77
+ subject._dump "dump.sql"
78
+ end
79
+ end
80
+
81
+ describe "#_load" do
82
+ it "do not load anything" do
83
+ subject.should_not_receive(:`)
84
+ subject._load "dump.sql"
85
+ end
86
+ end
87
+ end
88
+ end
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,9 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
11
 
12
12
  rspec_exclusions = {}
13
13
  rspec_exclusions[:skip_jdbc] = true if SequelRails.jruby?
14
+ rspec_exclusions[:postgres] = true unless ENV["TEST_ADAPTER"]=="postgresql"
15
+ rspec_exclusions[:mysql] = true unless ["mysql", "mysql2"].include? ENV["TEST_ADAPTER"]
16
+ rspec_exclusions[:sqlite] = true unless ENV["TEST_ADAPTER"]=="sqlite3"
14
17
 
15
18
  RSpec.configure do |config|
16
19
  config.treat_symbols_as_metadata_keys_with_true_values = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brasten Sager (brasten)
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-16 00:00:00.000000000 Z
12
+ date: 2013-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel
@@ -111,7 +111,6 @@ extra_rdoc_files:
111
111
  - LICENSE
112
112
  - README.md
113
113
  files:
114
- - .document
115
114
  - .gitignore
116
115
  - .rspec
117
116
  - .travis.yml
@@ -144,6 +143,7 @@ files:
144
143
  - lib/sequel_rails/sequel/database/active_support_notification.rb
145
144
  - lib/sequel_rails/sequel/plugins/rails_extensions.rb
146
145
  - lib/sequel_rails/session_store.rb
146
+ - lib/sequel_rails/shellwords.rb
147
147
  - lib/sequel_rails/storage.rb
148
148
  - lib/sequel_rails/storage/abstract.rb
149
149
  - lib/sequel_rails/storage/jdbc.rb
@@ -168,11 +168,15 @@ files:
168
168
  - spec/lib/sequel_rails/railtie_spec.rb
169
169
  - spec/lib/sequel_rails/railties/database_rake_spec.rb
170
170
  - spec/lib/sequel_rails/railties/log_subscriber_spec.rb
171
+ - spec/lib/sequel_rails/storage/mysql_spec.rb
172
+ - spec/lib/sequel_rails/storage/postgres_spec.rb
173
+ - spec/lib/sequel_rails/storage/sqlite_spec.rb
171
174
  - spec/lib/sequel_rails/storage_spec.rb
172
175
  - spec/spec_helper.rb
173
176
  - tasks/spec.rake
174
- homepage: https://github.com/TalentBox/sequel-rails
175
- licenses: []
177
+ homepage: http://talentbox.github.io/sequel-rails/
178
+ licenses:
179
+ - MIT
176
180
  metadata: {}
177
181
  post_install_message:
178
182
  rdoc_options:
@@ -191,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
195
  version: '0'
192
196
  requirements: []
193
197
  rubyforge_project:
194
- rubygems_version: 2.0.3
198
+ rubygems_version: 2.1.6
195
199
  signing_key:
196
200
  specification_version: 4
197
201
  summary: Use Sequel with Rails 3
@@ -211,5 +215,8 @@ test_files:
211
215
  - spec/lib/sequel_rails/railtie_spec.rb
212
216
  - spec/lib/sequel_rails/railties/database_rake_spec.rb
213
217
  - spec/lib/sequel_rails/railties/log_subscriber_spec.rb
218
+ - spec/lib/sequel_rails/storage/mysql_spec.rb
219
+ - spec/lib/sequel_rails/storage/postgres_spec.rb
220
+ - spec/lib/sequel_rails/storage/sqlite_spec.rb
214
221
  - spec/lib/sequel_rails/storage_spec.rb
215
222
  - spec/spec_helper.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE