sequel-rails 0.1.8 → 0.4.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/.gitignore +1 -0
  2. data/.rspec +3 -0
  3. data/.travis.yml +12 -0
  4. data/Gemfile +13 -16
  5. data/History.md +142 -0
  6. data/README.md +124 -0
  7. data/Rakefile +6 -30
  8. data/config.ru +7 -0
  9. data/lib/generators/sequel.rb +11 -8
  10. data/lib/generators/sequel/migration/migration_generator.rb +36 -11
  11. data/lib/generators/sequel/migration/templates/migration.rb.erb +48 -0
  12. data/lib/generators/sequel/model/model_generator.rb +8 -2
  13. data/lib/generators/sequel/model/templates/migration.rb.erb +16 -0
  14. data/lib/generators/sequel/model/templates/{model.rb → model.rb.erb} +4 -1
  15. data/lib/generators/sequel/observer/observer_generator.rb +2 -2
  16. data/lib/generators/sequel/observer/templates/{observer.rb → observer.rb.erb} +0 -0
  17. data/lib/sequel-rails.rb +1 -1
  18. data/lib/sequel_rails.rb +2 -0
  19. data/lib/sequel_rails/configuration.rb +64 -0
  20. data/lib/sequel_rails/migrations.rb +22 -0
  21. data/lib/sequel_rails/railtie.rb +94 -0
  22. data/lib/sequel_rails/railties/controller_runtime.rb +40 -0
  23. data/lib/sequel_rails/railties/database.rake +175 -0
  24. data/lib/sequel_rails/railties/i18n_support.rb +10 -0
  25. data/lib/sequel_rails/railties/log_subscriber.rb +56 -0
  26. data/lib/sequel_rails/sequel/database/active_support_notification.rb +28 -0
  27. data/lib/sequel_rails/sequel/plugins/rails_extensions.rb +35 -0
  28. data/lib/sequel_rails/session_store.rb +80 -0
  29. data/lib/sequel_rails/storage.rb +58 -0
  30. data/lib/sequel_rails/storage/abstract.rb +52 -0
  31. data/lib/sequel_rails/storage/jdbc.rb +45 -0
  32. data/lib/sequel_rails/storage/mysql.rb +31 -0
  33. data/lib/sequel_rails/storage/mysql2.rb +6 -0
  34. data/lib/sequel_rails/storage/postgres.rb +22 -0
  35. data/lib/sequel_rails/storage/sqlite.rb +26 -0
  36. data/lib/sequel_rails/version.rb +3 -0
  37. data/sequel-rails.gemspec +22 -86
  38. data/spec/internal/app/models/user.rb +2 -0
  39. data/spec/internal/config/database.yml +7 -0
  40. data/spec/internal/config/routes.rb +3 -0
  41. data/spec/internal/db/schema.rb +8 -0
  42. data/spec/internal/public/favicon.ico +0 -0
  43. data/spec/lib/generators/sequel/migration_spec.rb +256 -0
  44. data/spec/lib/sequel_rails/railtie_spec.rb +85 -0
  45. data/spec/lib/sequel_rails/railties/log_subscriber_spec.rb +29 -0
  46. data/spec/lib/sequel_rails/storage_spec.rb +108 -0
  47. data/spec/spec_helper.rb +30 -16
  48. data/tasks/spec.rake +63 -29
  49. metadata +194 -142
  50. data/CHANGELOG +0 -15
  51. data/README.rdoc +0 -86
  52. data/VERSION +0 -1
  53. data/autotest/discover.rb +0 -1
  54. data/lib/generators/sequel/migration/templates/migration.rb +0 -16
  55. data/lib/sequel-rails/configuration.rb +0 -61
  56. data/lib/sequel-rails/migrations.rb +0 -30
  57. data/lib/sequel-rails/railtie.rb +0 -90
  58. data/lib/sequel-rails/railties/benchmarking_mixin.rb +0 -23
  59. data/lib/sequel-rails/railties/controller_runtime.rb +0 -43
  60. data/lib/sequel-rails/railties/database.rake +0 -148
  61. data/lib/sequel-rails/railties/i18n_support.rb +0 -12
  62. data/lib/sequel-rails/railties/log_subscriber.rb +0 -31
  63. data/lib/sequel-rails/runtime.rb +0 -14
  64. data/lib/sequel-rails/session_store.rb +0 -82
  65. data/lib/sequel-rails/setup.rb +0 -19
  66. data/lib/sequel-rails/storage.rb +0 -210
  67. data/spec/rcov.opts +0 -6
  68. data/spec/setup_spec.rb +0 -7
  69. data/spec/spec.opts +0 -4
  70. data/tasks/ci.rake +0 -1
  71. data/tasks/clean.rake +0 -6
  72. data/tasks/metrics.rake +0 -37
  73. data/tasks/yard.rake +0 -9
  74. data/tasks/yardstick.rake +0 -20
@@ -0,0 +1,3 @@
1
+ module SequelRails
2
+ VERSION = "0.4.0.pre"
3
+ end
data/sequel-rails.gemspec CHANGED
@@ -1,93 +1,29 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
5
3
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{sequel-rails}
8
- s.version = "0.1.8"
4
+ require "sequel_rails/version"
9
5
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Brasten Sager (brasten)"]
12
- s.date = %q{2010-08-31}
13
- s.description = %q{Integrate Sequel with Rails 3}
14
- s.email = %q{brasten@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "CHANGELOG",
23
- "Gemfile",
24
- "LICENSE",
25
- "README.rdoc",
26
- "Rakefile",
27
- "VERSION",
28
- "autotest/discover.rb",
29
- "lib/generators/sequel.rb",
30
- "lib/generators/sequel/migration/migration_generator.rb",
31
- "lib/generators/sequel/migration/templates/migration.rb",
32
- "lib/generators/sequel/model/model_generator.rb",
33
- "lib/generators/sequel/model/templates/model.rb",
34
- "lib/generators/sequel/observer/observer_generator.rb",
35
- "lib/generators/sequel/observer/templates/observer.rb",
36
- "lib/sequel-rails.rb",
37
- "lib/sequel-rails/configuration.rb",
38
- "lib/sequel-rails/migrations.rb",
39
- "lib/sequel-rails/railtie.rb",
40
- "lib/sequel-rails/railties/benchmarking_mixin.rb",
41
- "lib/sequel-rails/railties/controller_runtime.rb",
42
- "lib/sequel-rails/railties/database.rake",
43
- "lib/sequel-rails/railties/i18n_support.rb",
44
- "lib/sequel-rails/railties/log_subscriber.rb",
45
- "lib/sequel-rails/runtime.rb",
46
- "lib/sequel-rails/session_store.rb",
47
- "lib/sequel-rails/setup.rb",
48
- "lib/sequel-rails/storage.rb",
49
- "sequel-rails.gemspec",
50
- "spec/rcov.opts",
51
- "spec/setup_spec.rb",
52
- "spec/spec.opts",
53
- "spec/spec_helper.rb",
54
- "tasks/ci.rake",
55
- "tasks/clean.rake",
56
- "tasks/metrics.rake",
57
- "tasks/spec.rake",
58
- "tasks/yard.rake",
59
- "tasks/yardstick.rake"
60
- ]
61
- s.homepage = %q{http://github.com/brasten/sequel-rails}
62
- s.rdoc_options = ["--charset=UTF-8"]
6
+ Gem::Specification.new do |s|
7
+ s.name = "sequel-rails"
8
+ s.version = SequelRails::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Brasten Sager (brasten)", "Jonathan TRON"]
11
+ s.email = ["brasten@gmail.com", "jonathan.tron@metrilio.com"]
12
+ s.homepage = "https://github.com/TalentBox/sequel-rails"
13
+ s.description = "Integrate Sequel with Rails 3"
14
+ s.summary = "Use Sequel with Rails 3"
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
63
18
  s.require_paths = ["lib"]
64
- s.rubygems_version = %q{1.3.6}
65
- s.summary = %q{Use Sequel with Rails 3}
66
- s.test_files = [
67
- "spec/setup_spec.rb",
68
- "spec/spec_helper.rb"
69
- ]
19
+ s.extra_rdoc_files = ["LICENSE", "README.md"]
20
+ s.rdoc_options = ["--charset=UTF-8"]
70
21
 
71
- if s.respond_to? :specification_version then
72
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
73
- s.specification_version = 3
22
+ s.add_runtime_dependency("sequel", ["~> 3.28"])
23
+ s.add_runtime_dependency("railties", ["~> 3.2.0"])
74
24
 
75
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
76
- s.add_runtime_dependency(%q<sequel>, ["~> 3.13"])
77
- s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0"])
78
- s.add_runtime_dependency(%q<actionpack>, ["~> 3.0.0"])
79
- s.add_runtime_dependency(%q<railties>, ["~> 3.0.0"])
80
- else
81
- s.add_dependency(%q<sequel>, ["~> 3.13"])
82
- s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
83
- s.add_dependency(%q<actionpack>, ["~> 3.0.0"])
84
- s.add_dependency(%q<railties>, ["~> 3.0.0"])
85
- end
86
- else
87
- s.add_dependency(%q<sequel>, ["~> 3.13"])
88
- s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
89
- s.add_dependency(%q<actionpack>, ["~> 3.0.0"])
90
- s.add_dependency(%q<railties>, ["~> 3.0.0"])
91
- end
25
+ s.add_development_dependency "rake", ">= 0.8.7"
26
+ s.add_development_dependency "rspec", "~> 2.7.0"
27
+ s.add_development_dependency "combustion", "~> 0.3.1"
28
+ s.add_development_dependency "generator_spec", "~> 0.8.7"
92
29
  end
93
-
@@ -0,0 +1,2 @@
1
+ class User < Sequel::Model
2
+ end
@@ -0,0 +1,7 @@
1
+ test:
2
+ adapter: "<%= ENV["TEST_ADAPTER"] || "postgresql" %>"
3
+ database: "<%= ENV["TEST_DATABASE"] || "sequel_rails_test" %>"
4
+ owner: "<%= ENV["TEST_OWNER"] || ENV["USER"] %>"
5
+ username: "<%= ENV["TEST_USERNAME"] || ENV["USER"] %>"
6
+ password: "<%= ENV["TEST_PASSWORD"] %>"
7
+ encoding: "<%= ENV["TEST_ENCODING"] || "unicode" %>"
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ #
3
+ end
@@ -0,0 +1,8 @@
1
+ Sequel.migration do
2
+ change do
3
+ create_table :users do
4
+ primary_key :id
5
+ String :email
6
+ end
7
+ end
8
+ end
File without changes
@@ -0,0 +1,256 @@
1
+ require "spec_helper"
2
+ require "generator_spec/test_case"
3
+ require "generators/sequel/migration/migration_generator"
4
+
5
+ describe Sequel::Generators::MigrationGenerator do
6
+ include GeneratorSpec::TestCase
7
+ destination File.expand_path("../../../../internal/tmp", __FILE__)
8
+
9
+ before { prepare_destination }
10
+
11
+ it "generates different ids for simultaneously generated migrations" do
12
+ migrations = ["create_authors", "create_users"]
13
+ first_number, second_number = migrations.collect do |migration_name|
14
+ run_generator [migration_name]
15
+ file_name = migration_file_name "db/migrate/#{migration_name}.rb"
16
+ File.basename(file_name).split("_").first
17
+ end
18
+ first_number.should_not == second_number
19
+ end
20
+
21
+ it "refuses to generate migration with invalid filename" do
22
+ expect do
23
+ run_generator ["add_something:datetime"]
24
+ end.to raise_error
25
+ end
26
+
27
+ context "when name starts with create" do
28
+ before { run_generator ["create_authors"] }
29
+ it "creates a new migration using change to create the table" do
30
+ destination_root.should have_structure {
31
+ directory "db" do
32
+ directory "migrate" do
33
+ migration "create_authors" do
34
+ contains <<-CONTENT.strip_heredoc
35
+ Sequel.migration do
36
+ change do
37
+ create_table :authors do
38
+ primary_key :id
39
+ end
40
+ end
41
+ end
42
+ CONTENT
43
+ end
44
+ end
45
+ end
46
+ }
47
+ end
48
+ end
49
+
50
+ context "when name starts with drop" do
51
+ context "and does not contains _from_" do
52
+ before { run_generator ["drop_author"] }
53
+ it "creates a new migration using up/down to drop the table" do
54
+ destination_root.should have_structure {
55
+ directory "db" do
56
+ directory "migrate" do
57
+ migration "drop_author" do
58
+ contains <<-CONTENT.strip_heredoc
59
+ Sequel.migration do
60
+ up do
61
+ drop_table :authors
62
+ end
63
+
64
+ down do
65
+ create_table :authors do
66
+ end
67
+ end
68
+ end
69
+ CONTENT
70
+ end
71
+ end
72
+ end
73
+ }
74
+ end
75
+ end
76
+ context "and contains _from_" do
77
+ before { run_generator ["drop_salary_from_authors"] }
78
+ it "creates a new migration using up/down to drop the column from table" do
79
+ destination_root.should have_structure {
80
+ directory "db" do
81
+ directory "migrate" do
82
+ migration "drop_salary_from_authors" do
83
+ contains <<-CONTENT.strip_heredoc
84
+ Sequel.migration do
85
+ up do
86
+ alter_table :authors do
87
+ end
88
+ end
89
+
90
+ down do
91
+ alter_table :authors do
92
+ end
93
+ end
94
+ end
95
+ CONTENT
96
+ end
97
+ end
98
+ end
99
+ }
100
+ end
101
+ end
102
+ end
103
+
104
+ context "when name starts with add" do
105
+ context "and does not contains _to_ nor _from_" do
106
+ before { run_generator ["add_new_indexes"] }
107
+ it "creates a new migration using up/down" do
108
+ destination_root.should have_structure {
109
+ directory "db" do
110
+ directory "migrate" do
111
+ migration "add_new_indexes" do
112
+ contains <<-CONTENT.strip_heredoc
113
+ Sequel.migration do
114
+ up do
115
+ alter_table :add_new_indexes do
116
+ end
117
+ end
118
+
119
+ down do
120
+ alter_table :add_new_indexes do
121
+ end
122
+ end
123
+ end
124
+ CONTENT
125
+ end
126
+ end
127
+ end
128
+ }
129
+ end
130
+ end
131
+ context "and contains _to_" do
132
+ before { run_generator ["add_salary_to_authors"] }
133
+ it "creates a new migration using change to add the column to the table" do
134
+ destination_root.should have_structure {
135
+ directory "db" do
136
+ directory "migrate" do
137
+ migration "add_salary_to_authors" do
138
+ contains <<-CONTENT.strip_heredoc
139
+ Sequel.migration do
140
+ change do
141
+ alter_table :authors do
142
+ end
143
+ end
144
+ end
145
+ CONTENT
146
+ end
147
+ end
148
+ end
149
+ }
150
+ end
151
+ end
152
+ context "and contains _from_" do
153
+ before { run_generator ["add_salary_from_authors"] }
154
+ it "creates a new migration using change to add the column to the table" do
155
+ destination_root.should have_structure {
156
+ directory "db" do
157
+ directory "migrate" do
158
+ migration "add_salary_from_authors" do
159
+ contains <<-CONTENT.strip_heredoc
160
+ Sequel.migration do
161
+ change do
162
+ alter_table :authors do
163
+ end
164
+ end
165
+ end
166
+ CONTENT
167
+ end
168
+ end
169
+ end
170
+ }
171
+ end
172
+ end
173
+ end
174
+
175
+ context "when name starts with remove" do
176
+ context "and does not contains _to_ nor _from_" do
177
+ before { run_generator ["remove_new_indexes"] }
178
+ it "creates a new migration using up/down" do
179
+ destination_root.should have_structure {
180
+ directory "db" do
181
+ directory "migrate" do
182
+ migration "remove_new_indexes" do
183
+ contains <<-CONTENT.strip_heredoc
184
+ Sequel.migration do
185
+ up do
186
+ alter_table :remove_new_indexes do
187
+ end
188
+ end
189
+
190
+ down do
191
+ alter_table :remove_new_indexes do
192
+ end
193
+ end
194
+ end
195
+ CONTENT
196
+ end
197
+ end
198
+ end
199
+ }
200
+ end
201
+ end
202
+ context "and contains _to_" do
203
+ before { run_generator ["remove_salary_to_authors"] }
204
+ it "creates a new migration using up/down to remove the column from the table" do
205
+ destination_root.should have_structure {
206
+ directory "db" do
207
+ directory "migrate" do
208
+ migration "remove_salary_to_authors" do
209
+ contains <<-CONTENT.strip_heredoc
210
+ Sequel.migration do
211
+ up do
212
+ alter_table :authors do
213
+ end
214
+ end
215
+
216
+ down do
217
+ alter_table :authors do
218
+ end
219
+ end
220
+ end
221
+ CONTENT
222
+ end
223
+ end
224
+ end
225
+ }
226
+ end
227
+ end
228
+ context "and contains _from_" do
229
+ before { run_generator ["remove_salary_from_authors"] }
230
+ it "creates a new migration using change to remove the column from the table" do
231
+ destination_root.should have_structure {
232
+ directory "db" do
233
+ directory "migrate" do
234
+ migration "remove_salary_from_authors" do
235
+ contains <<-CONTENT.strip_heredoc
236
+ Sequel.migration do
237
+ up do
238
+ alter_table :authors do
239
+ end
240
+ end
241
+
242
+ down do
243
+ alter_table :authors do
244
+ end
245
+ end
246
+ end
247
+ CONTENT
248
+ end
249
+ end
250
+ end
251
+ }
252
+ end
253
+ end
254
+ end
255
+
256
+ end
@@ -0,0 +1,85 @@
1
+ require "spec_helper"
2
+
3
+ describe SequelRails::Railtie do
4
+ it "registers ::Sequel::Railtie::LogSubscriber to receive :sequel notification" do
5
+ ActiveSupport::LogSubscriber.log_subscribers.select do |subscriber|
6
+ subscriber.is_a?(SequelRails::Railties::LogSubscriber)
7
+ end.should have(1).item
8
+ end
9
+
10
+ context "configures generator to use Sequel" do
11
+ it "as orm" do
12
+ Combustion::Application.config.generators.options[:rails][:orm].should == :sequel
13
+ end
14
+
15
+ it "for migrations" do
16
+ Combustion::Application.config.generators.options[:sequel][:migration].should be true
17
+ end
18
+ end
19
+
20
+ it "configures rails to use fancy pants logging" do
21
+ Combustion::Application.config.rails_fancy_pants_logging.should be true
22
+ end
23
+
24
+ context "configures action dispatch's rescue responses" do
25
+ let(:rescue_responses) do
26
+ Combustion::Application.config.action_dispatch.rescue_responses
27
+ end
28
+
29
+ it "to handle Sequel::Plugins::RailsExtensions::ModelNotFound with :not_found" do
30
+ rescue_responses["Sequel::Plugins::RailsExtensions::ModelNotFound"].should == :not_found
31
+ end
32
+
33
+ it "to handle Sequel::ValidationFailed with :unprocessable_entity" do
34
+ rescue_responses["Sequel::ValidationFailed"].should == :unprocessable_entity
35
+ end
36
+
37
+ it "to handle Sequel::NoExistingObject with :unprocessable_entity" do
38
+ rescue_responses["Sequel::NoExistingObject"].should == :unprocessable_entity
39
+ end
40
+ end
41
+
42
+ it "adds it's own database's rake tasks" do
43
+ pending "need to find a way to spec it"
44
+ end
45
+
46
+ it "stores it's own config in app.config.sequel" do
47
+ Combustion::Application.config.sequel.should be_instance_of SequelRails::Configuration
48
+ end
49
+
50
+ it "sets Rails.logger as default logger for its configuration" do
51
+ Combustion::Application.config.sequel.logger.should be Rails.logger
52
+ end
53
+
54
+ it "configures Sequel::Model instances for i18n" do
55
+ User.new.i18n_scope.should == :sequel
56
+ end
57
+
58
+ it "adds Sequel runtime to controller for logging" do
59
+ ActionController::Base.included_modules.should include(
60
+ SequelRails::Railties::ControllerRuntime
61
+ )
62
+ end
63
+
64
+ context "Sequel::Model is configured" do
65
+ let(:plugins) { Sequel::Model.plugins }
66
+ it "to use :active_model plugin" do
67
+ plugins.should include Sequel::Plugins::ActiveModel
68
+ end
69
+ it "to use :validation_helpers plugin" do
70
+ plugins.should include Sequel::Plugins::ValidationHelpers
71
+ end
72
+ it "to use :rails_extensions plugin" do
73
+ plugins.should include Sequel::Plugins::RailsExtensions
74
+ end
75
+ it "to not raise on save failure" do
76
+ Sequel::Model.raise_on_save_failure.should be false
77
+ end
78
+ end
79
+
80
+ it "configures database in Sequel" do
81
+ expect do
82
+ Sequel::Model.db.test_connection
83
+ end.to_not raise_error Sequel::Error
84
+ end
85
+ end