rom-rails 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile +2 -2
- data/Rakefile +1 -1
- data/lib/rom/rails/railtie.rb +61 -16
- data/lib/rom/rails/tasks/db.rake +11 -0
- data/lib/rom/rails/version.rb +1 -1
- data/spec/dummy/Rakefile +0 -8
- data/spec/dummy/app/forms/update_user_form.rb +1 -1
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/database.yml +1 -5
- data/spec/dummy/config/initializers/rom.rb +2 -7
- data/spec/dummy/spec/integration/activerecord_setup.rb +6 -0
- data/spec/unit/form_spec.rb +4 -11
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d53fad0999e88095261c12196674bf05ef9754eb
|
4
|
+
data.tar.gz: 134a8100ee7b0b4967315b3ce342a1526b9280e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff2d1b07af8d3e2ad0263ea1f7fa1d433dc1f3da4c801710f51daa778dc9b903224747bdd55a9ca9bb232103a4561ef332161a6db12bd367a9ffe6e130fd127b
|
7
|
+
data.tar.gz: ebf50d904cd43b7be7addd0c9167921e4ae9924250b8e69aea2bbd8f9f705020f80865fc5336b8a1ee67480b8b6833d241250cb3c732afc4ed2138d2bf67c571
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## v0.3.3 2015-05-22
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* `db:setup` task which works OOTB with rom-sql tasks (solnic)
|
6
|
+
|
7
|
+
### Changed
|
8
|
+
|
9
|
+
* `MissingRepositoryConfigError` is raised when repositories are not configured (solnic)
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
|
13
|
+
* The railitie no longer set `nil` as default repository when ActiveRecord is not present (solnic)
|
14
|
+
|
15
|
+
[Compare v0.3.2...v0.3.3](https://github.com/rom-rb/rom-rails/compare/v0.3.2...v0.3.3)
|
16
|
+
|
1
17
|
## v0.3.2 2015-05-17
|
2
18
|
|
3
19
|
### Fixed
|
data/Gemfile
CHANGED
@@ -4,11 +4,12 @@ gemspec
|
|
4
4
|
|
5
5
|
RAILS_VERSION = '4.2.1'
|
6
6
|
|
7
|
-
%w(railties activemodel actionview actionpack).each do |name|
|
7
|
+
%w(railties activemodel actionview actionpack activerecord).each do |name|
|
8
8
|
gem name, RAILS_VERSION
|
9
9
|
end
|
10
10
|
|
11
11
|
gem 'sqlite3', platforms: [:mri, :rbx]
|
12
|
+
gem 'byebug', platforms: :mri
|
12
13
|
|
13
14
|
platforms :jruby do
|
14
15
|
gem 'jdbc-sqlite3'
|
@@ -18,7 +19,6 @@ group :test do
|
|
18
19
|
gem 'rack-test'
|
19
20
|
gem 'rom', github: 'rom-rb/rom', branch: 'master'
|
20
21
|
gem 'rom-sql', github: 'rom-rb/rom-sql', branch: 'master'
|
21
|
-
gem 'byebug', platforms: :mri
|
22
22
|
gem 'rspec-rails', '~> 3.1'
|
23
23
|
gem 'codeclimate-test-reporter', require: nil
|
24
24
|
gem 'database_cleaner'
|
data/Rakefile
CHANGED
data/lib/rom/rails/railtie.rb
CHANGED
@@ -10,6 +10,47 @@ Spring.after_fork { ROM::Rails::Railtie.disconnect } if defined?(Spring)
|
|
10
10
|
module ROM
|
11
11
|
module Rails
|
12
12
|
class Railtie < ::Rails::Railtie
|
13
|
+
COMPONENT_DIRS = %w(relations mappers commands).freeze
|
14
|
+
|
15
|
+
MissingRepositoryConfigError = Class.new(StandardError)
|
16
|
+
|
17
|
+
# @api public
|
18
|
+
def self.setup_repositories
|
19
|
+
raise(
|
20
|
+
MissingRepositoryConfigError,
|
21
|
+
"seems like you didn't configure any repositories"
|
22
|
+
) unless config.rom.repositories.any?
|
23
|
+
|
24
|
+
ROM.setup(config.rom.repositories)
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
# @api public
|
29
|
+
def self.finalize
|
30
|
+
ROM.finalize
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
# If there's no default repository configured, try to infer it from
|
35
|
+
# other sources, e.g. ActiveRecord.
|
36
|
+
#
|
37
|
+
# @api private
|
38
|
+
def self.infer_default_repository
|
39
|
+
return unless active_record?
|
40
|
+
spec = ROM::Rails::ActiveRecord::Configuration.call
|
41
|
+
[:sql, spec[:uri], spec[:options]]
|
42
|
+
end
|
43
|
+
|
44
|
+
# @api private
|
45
|
+
def self.active_record?
|
46
|
+
defined?(::ActiveRecord)
|
47
|
+
end
|
48
|
+
|
49
|
+
# @api private
|
50
|
+
def before_initialize
|
51
|
+
config.rom = Configuration.new
|
52
|
+
end
|
53
|
+
|
13
54
|
initializer 'rom.configure_action_controller' do
|
14
55
|
ActiveSupport.on_load(:action_controller) do
|
15
56
|
ActionController::Base.send(:include, ControllerExtension)
|
@@ -17,17 +58,21 @@ module ROM
|
|
17
58
|
end
|
18
59
|
|
19
60
|
initializer 'rom.adjust_eager_load_paths' do |app|
|
20
|
-
paths =
|
61
|
+
paths = COMPONENT_DIRS.map do |directory|
|
21
62
|
::Rails.root.join('app', directory).to_s
|
22
63
|
end
|
23
64
|
|
24
65
|
app.config.eager_load_paths -= paths
|
25
66
|
end
|
26
67
|
|
68
|
+
rake_tasks do
|
69
|
+
load "rom/rails/tasks/db.rake" unless self.class.active_record?
|
70
|
+
end
|
71
|
+
|
27
72
|
# Make `ROM::Rails::Configuration` instance available to the user via
|
28
73
|
# `Rails.application.config` before other initializers run.
|
29
74
|
config.before_initialize do |_app|
|
30
|
-
|
75
|
+
before_initialize
|
31
76
|
end
|
32
77
|
|
33
78
|
# Reload ROM-related application code on each request.
|
@@ -40,7 +85,7 @@ module ROM
|
|
40
85
|
#
|
41
86
|
# @example
|
42
87
|
# ROM::Rails::Railtie.configure do |config|
|
43
|
-
# config.repositories[:
|
88
|
+
# config.repositories[:default] = [:yaml, 'yaml:///data']
|
44
89
|
# end
|
45
90
|
#
|
46
91
|
# @api public
|
@@ -52,45 +97,45 @@ module ROM
|
|
52
97
|
end
|
53
98
|
end
|
54
99
|
|
100
|
+
# TODO: Add `ROM.env.disconnect` to core.
|
101
|
+
#
|
102
|
+
# @api private
|
55
103
|
def disconnect
|
56
|
-
# TODO: Add `ROM.env.disconnect` to core.
|
57
104
|
ROM.env.repositories.each_value(&:disconnect)
|
58
105
|
end
|
59
106
|
|
107
|
+
# @api private
|
60
108
|
def setup
|
61
109
|
if ROM.env
|
62
110
|
ROM.setup(ROM.env.repositories)
|
63
111
|
else
|
64
112
|
repositories = config.rom.repositories
|
65
113
|
|
66
|
-
|
67
|
-
|
68
|
-
|
114
|
+
if self.class.active_record?
|
115
|
+
repositories[:default] ||= self.class.infer_default_repository
|
116
|
+
end
|
69
117
|
|
70
|
-
|
118
|
+
self.class.setup_repositories
|
71
119
|
end
|
72
120
|
load_all
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
def infer_default_repository
|
77
|
-
return unless defined?(::ActiveRecord)
|
78
|
-
spec = ActiveRecord::Configuration.call
|
79
|
-
[:sql, spec[:uri], spec[:options]]
|
121
|
+
self.class.finalize
|
80
122
|
end
|
81
123
|
|
124
|
+
# @api private
|
82
125
|
def load_all
|
83
|
-
|
126
|
+
COMPONENT_DIRS.each do |type|
|
84
127
|
load_files(type)
|
85
128
|
end
|
86
129
|
end
|
87
130
|
|
131
|
+
# @api private
|
88
132
|
def load_files(type)
|
89
133
|
Dir[root.join("app/#{type}/**/*.rb").to_s].each do |path|
|
90
134
|
require_dependency(path)
|
91
135
|
end
|
92
136
|
end
|
93
137
|
|
138
|
+
# @api private
|
94
139
|
def root
|
95
140
|
::Rails.root
|
96
141
|
end
|
data/lib/rom/rails/version.rb
CHANGED
data/spec/dummy/Rakefile
CHANGED
@@ -6,11 +6,3 @@ require File.expand_path('../config/application', __FILE__)
|
|
6
6
|
Dummy::Application.load_tasks
|
7
7
|
|
8
8
|
require 'rom/sql/rake_task'
|
9
|
-
|
10
|
-
namespace :db do
|
11
|
-
task :setup do
|
12
|
-
scheme = RUBY_ENGINE == 'jruby' ? 'jdbc:sqlite' : 'sqlite'
|
13
|
-
ROM.setup(:sql, "#{scheme}://#{Rails.root}/db/#{Rails.env}.sqlite3")
|
14
|
-
ROM.finalize
|
15
|
-
end
|
16
|
-
end
|
@@ -1,10 +1,5 @@
|
|
1
1
|
ROM::Rails::Railtie.configure do |config|
|
2
|
-
|
3
|
-
|
4
|
-
.merge(root: Rails.root)
|
5
|
-
)
|
6
|
-
|
7
|
-
config.repositories[:default] = [:sql, db_config[:uri], db_config[:options]]
|
8
|
-
|
2
|
+
scheme = RUBY_ENGINE == 'jruby' ? 'jdbc:sqlite' : 'sqlite'
|
3
|
+
config.repositories[:default] = [:sql, "#{scheme}://#{Rails.root}/db/#{Rails.env}.sqlite3"]
|
9
4
|
config.repositories[:test] = [:test_adapter, foo: :bar]
|
10
5
|
end
|
data/spec/unit/form_spec.rb
CHANGED
@@ -213,6 +213,7 @@ describe 'Form' do
|
|
213
213
|
it "recovers from database errors" do
|
214
214
|
form = Class.new(ROM::Model::Form) do
|
215
215
|
commands users: :create
|
216
|
+
|
216
217
|
input do
|
217
218
|
set_model_name 'User'
|
218
219
|
|
@@ -220,24 +221,16 @@ describe 'Form' do
|
|
220
221
|
end
|
221
222
|
|
222
223
|
def commit!(*args)
|
223
|
-
|
224
224
|
users.try {
|
225
225
|
raise ROM::SQL::ConstraintError.new(RuntimeError.new("duplicate key"))
|
226
226
|
}
|
227
|
-
|
228
227
|
end
|
229
228
|
end
|
230
229
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
expect(result.errors[:email]).to eq []
|
236
|
-
expect(result.errors[:base]).to eq ["a database error prevented saving this form"]
|
230
|
+
expect {
|
231
|
+
form.build(email: 'test@example.com').save
|
232
|
+
}.to raise_error(ROM::SQL::ConstraintError)
|
237
233
|
end
|
238
|
-
|
239
|
-
|
240
|
-
|
241
234
|
end
|
242
235
|
|
243
236
|
describe "#attributes" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rom
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- lib/rom/rails/model/validator.rb
|
183
183
|
- lib/rom/rails/model/validator/uniqueness_validator.rb
|
184
184
|
- lib/rom/rails/railtie.rb
|
185
|
+
- lib/rom/rails/tasks/db.rake
|
185
186
|
- lib/rom/rails/version.rb
|
186
187
|
- rom-rails.gemspec
|
187
188
|
- spec/dummy/.rspec
|
@@ -241,6 +242,7 @@ files:
|
|
241
242
|
- spec/dummy/public/favicon.ico
|
242
243
|
- spec/dummy/public/robots.txt
|
243
244
|
- spec/dummy/spec/features/users_spec.rb
|
245
|
+
- spec/dummy/spec/integration/activerecord_setup.rb
|
244
246
|
- spec/dummy/spec/integration/form_with_injected_commands_spec.rb
|
245
247
|
- spec/dummy/spec/integration/initializer_spec.rb
|
246
248
|
- spec/dummy/spec/integration/logger_spec.rb
|
@@ -340,6 +342,7 @@ test_files:
|
|
340
342
|
- spec/dummy/public/favicon.ico
|
341
343
|
- spec/dummy/public/robots.txt
|
342
344
|
- spec/dummy/spec/features/users_spec.rb
|
345
|
+
- spec/dummy/spec/integration/activerecord_setup.rb
|
343
346
|
- spec/dummy/spec/integration/form_with_injected_commands_spec.rb
|
344
347
|
- spec/dummy/spec/integration/initializer_spec.rb
|
345
348
|
- spec/dummy/spec/integration/logger_spec.rb
|