rom-rails 0.3.1 → 0.3.2
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 +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +10 -0
- data/Gemfile +6 -2
- data/lib/generators/rom/commands_generator.rb +5 -1
- data/lib/generators/rom/mapper/templates/mapper.rb.erb +2 -0
- data/lib/generators/rom/mapper_generator.rb +5 -0
- data/lib/generators/rom/relation/templates/relation.rb.erb +8 -0
- data/lib/generators/rom/relation_generator.rb +20 -0
- data/lib/rom-rails.rb +2 -0
- data/lib/rom/rails/model/form.rb +16 -11
- data/lib/rom/rails/model/form/error_proxy.rb +56 -0
- data/lib/rom/rails/version.rb +1 -1
- data/rom-rails.gemspec +1 -1
- data/spec/dummy/Rakefile +10 -0
- data/spec/dummy/app/relations/dummy_relation.rb +4 -0
- data/spec/dummy/config/application.rb +2 -1
- data/spec/dummy/config/initializers/rom.rb +10 -0
- data/spec/dummy/config/locales/en.yml +7 -1
- data/spec/dummy/db/migrate/20141110205016_add_users.rb +7 -5
- data/spec/dummy/db/migrate/20150202194440_create_tasks.rb +5 -4
- data/spec/dummy/db/migrate/20150403194906_create_tags.rb +5 -4
- data/spec/dummy/lib/rom/test_adapter.rb +27 -0
- data/spec/dummy/spec/integration/initializer_spec.rb +11 -0
- data/spec/lib/generators/commands_generator_spec.rb +4 -4
- data/spec/lib/generators/mapper_generator_spec.rb +3 -1
- data/spec/lib/generators/relation_generator_spec.rb +19 -0
- data/spec/spec_helper.rb +11 -3
- data/spec/unit/form_spec.rb +32 -3
- data/spec/unit/validator_spec.rb +5 -3
- metadata +15 -11
- data/spec/dummy/db/schema.rb +0 -31
- data/spec/dummy/db/seeds.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ad7fe254e8fd3118cbdac07bf9bc51d0b686e32
|
4
|
+
data.tar.gz: 73527dafdfb2542cbc1dc30559dc56d66cfb5c08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5968c5f300b0e336727b13919b9a7204f2fb40dc541bf6818c7eb05eb913ee3c82b78375d07ea16aec8fdbe2834a914dc034966ff28d7f45716c2fe44c52cb8
|
7
|
+
data.tar.gz: fe6ab28f3f240bdba00fe1282ee9aa34a42f5f51230b1329b17fdb39ae3352ece725cbf89a97e39ff29754b61e0fdf67e5038f302d40dd8c22e872755327f0b3
|
data/.travis.yml
CHANGED
@@ -4,7 +4,7 @@ cache: bundler
|
|
4
4
|
bundler_args: --without yard guard benchmarks
|
5
5
|
env:
|
6
6
|
- CODECLIMATE_REPO_TOKEN=87c9080bda25bce8e63a294f99312345c144c0f6d5eedf400fd753356fbf7dcf
|
7
|
-
script: "RAILS_ENV=test bundle exec rake app:db:
|
7
|
+
script: "RAILS_ENV=test bundle exec rake app:db:reset app:spec"
|
8
8
|
rvm:
|
9
9
|
- 2.0
|
10
10
|
- 2.1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## v0.3.2 2015-05-17
|
2
|
+
|
3
|
+
### Fixed
|
4
|
+
|
5
|
+
* Generator uses correct directory for commands (cflipse)
|
6
|
+
* Generators can now add `register_as` and `repository` settings (cflipse)
|
7
|
+
* Database errors are now wrapped in Form objects so they can be handled gracefully (cflipse)
|
8
|
+
|
9
|
+
[Compare v0.3.1...v0.3.2](https://github.com/rom-rb/rom-rails/compare/v0.3.1...v0.3.2)
|
10
|
+
|
1
11
|
## v0.3.1 2015-04-04
|
2
12
|
|
3
13
|
### Added
|
data/Gemfile
CHANGED
@@ -2,16 +2,20 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
|
5
|
+
RAILS_VERSION = '4.2.1'
|
6
|
+
|
7
|
+
%w(railties activemodel actionview actionpack).each do |name|
|
8
|
+
gem name, RAILS_VERSION
|
9
|
+
end
|
6
10
|
|
7
11
|
gem 'sqlite3', platforms: [:mri, :rbx]
|
8
12
|
|
9
13
|
platforms :jruby do
|
10
14
|
gem 'jdbc-sqlite3'
|
11
|
-
gem 'activerecord-jdbc-adapter'
|
12
15
|
end
|
13
16
|
|
14
17
|
group :test do
|
18
|
+
gem 'rack-test'
|
15
19
|
gem 'rom', github: 'rom-rb/rom', branch: 'master'
|
16
20
|
gem 'rom-sql', github: 'rom-rb/rom-sql', branch: 'master'
|
17
21
|
gem 'byebug', platforms: :mri
|
@@ -23,7 +23,11 @@ module ROM
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def command_file(command)
|
26
|
-
File.join('app', 'commands',
|
26
|
+
File.join('app', 'commands', command_dir, "#{command}.rb")
|
27
|
+
end
|
28
|
+
|
29
|
+
def command_dir
|
30
|
+
"#{class_name.downcase.singularize}_commands"
|
27
31
|
end
|
28
32
|
|
29
33
|
def relation
|
@@ -1,6 +1,14 @@
|
|
1
1
|
class <%= class_name %>Relation < ROM::Relation<%= "[:#{adapter}]" %>
|
2
|
+
<% if repository -%>
|
3
|
+
repository :<%= repository %>
|
4
|
+
<% else -%>
|
5
|
+
# repository :default
|
6
|
+
<% end -%>
|
7
|
+
|
2
8
|
dataset :<%= dataset %>
|
3
9
|
|
10
|
+
register_as :<%= register_as %>
|
11
|
+
|
4
12
|
# define your methods here ie:
|
5
13
|
#
|
6
14
|
# def all
|
@@ -8,6 +8,17 @@ module ROM
|
|
8
8
|
desc: "specify an adapter to use", required: true,
|
9
9
|
default: ROM.adapters.keys.first
|
10
10
|
|
11
|
+
class_option :repository,
|
12
|
+
banner: "--repository=repo",
|
13
|
+
desc: "specify a repository to connect to",
|
14
|
+
required: false
|
15
|
+
|
16
|
+
class_option :register,
|
17
|
+
banner: "--register=name",
|
18
|
+
desc: "specify the registration identifier",
|
19
|
+
required: false
|
20
|
+
|
21
|
+
|
11
22
|
def create_relation_file
|
12
23
|
template(
|
13
24
|
'relation.rb.erb',
|
@@ -24,6 +35,15 @@ module ROM
|
|
24
35
|
def adapter
|
25
36
|
options[:adapter]
|
26
37
|
end
|
38
|
+
|
39
|
+
def register_as
|
40
|
+
options[:register] || dataset
|
41
|
+
end
|
42
|
+
|
43
|
+
def repository
|
44
|
+
options[:repository]
|
45
|
+
end
|
46
|
+
|
27
47
|
end
|
28
48
|
end
|
29
49
|
end
|
data/lib/rom-rails.rb
CHANGED
data/lib/rom/rails/model/form.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rom/rails/model/form/class_interface'
|
2
|
+
require 'rom/rails/model/form/error_proxy'
|
2
3
|
|
3
4
|
module ROM
|
4
5
|
module Model
|
@@ -72,6 +73,13 @@ module ROM
|
|
72
73
|
# @api public
|
73
74
|
attr_reader :result
|
74
75
|
|
76
|
+
# Return any errors with the form
|
77
|
+
#
|
78
|
+
# @return [ErrorProxy]
|
79
|
+
#
|
80
|
+
# @api public
|
81
|
+
attr_reader :errors
|
82
|
+
|
75
83
|
delegate :model_name, :persisted?, :to_key, to: :model
|
76
84
|
alias_method :to_model, :model
|
77
85
|
|
@@ -84,7 +92,7 @@ module ROM
|
|
84
92
|
@params = params
|
85
93
|
@model = self.class.model.new(params.merge(options.slice(*self.class.key)))
|
86
94
|
@result = nil
|
87
|
-
@errors =
|
95
|
+
@errors = ErrorProxy.new
|
88
96
|
options.each { |key, value| instance_variable_set("@#{key}", value) }
|
89
97
|
end
|
90
98
|
|
@@ -103,7 +111,11 @@ module ROM
|
|
103
111
|
#
|
104
112
|
# @api public
|
105
113
|
def save(*args)
|
114
|
+
@errors.clear
|
106
115
|
@result = commit!(*args)
|
116
|
+
|
117
|
+
@errors.set @result.error if result.respond_to? :error
|
118
|
+
|
107
119
|
self
|
108
120
|
end
|
109
121
|
|
@@ -113,17 +125,18 @@ module ROM
|
|
113
125
|
#
|
114
126
|
# @api public
|
115
127
|
def success?
|
116
|
-
errors.
|
128
|
+
errors.success?
|
117
129
|
end
|
118
130
|
|
119
131
|
# Trigger validation and store errors (if any)
|
120
132
|
#
|
121
133
|
# @api public
|
122
134
|
def validate!
|
135
|
+
@errors.clear
|
123
136
|
validator = self.class::Validator.new(attributes)
|
124
137
|
validator.validate
|
125
138
|
|
126
|
-
@errors
|
139
|
+
@errors.set validator.errors
|
127
140
|
end
|
128
141
|
|
129
142
|
# Sanitize and coerce input params
|
@@ -137,14 +150,6 @@ module ROM
|
|
137
150
|
self.class.attributes[params]
|
138
151
|
end
|
139
152
|
|
140
|
-
# Return errors
|
141
|
-
#
|
142
|
-
# @return [ActiveModel::Errors]
|
143
|
-
#
|
144
|
-
# @api public
|
145
|
-
def errors
|
146
|
-
(result && result.error) || @errors
|
147
|
-
end
|
148
153
|
end
|
149
154
|
end
|
150
155
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module ROM
|
2
|
+
module Model
|
3
|
+
class Form
|
4
|
+
# Proxy for form errors
|
5
|
+
#
|
6
|
+
# This simple proxy forwards most messages to a wrapped
|
7
|
+
# ActiveModel::Errors object
|
8
|
+
#
|
9
|
+
# @api private
|
10
|
+
class ErrorProxy < SimpleDelegator
|
11
|
+
|
12
|
+
# @api private
|
13
|
+
def initialize
|
14
|
+
super ActiveModel::Errors.new([])
|
15
|
+
end
|
16
|
+
|
17
|
+
# update the current errors
|
18
|
+
#
|
19
|
+
# @param error [ActiveModel::Errors, ROM::Model::ValidatonError, object]
|
20
|
+
#
|
21
|
+
# When the argument is an AM Error object, or our wrapper around one,
|
22
|
+
# replace the wrapped object. Otherwise, add an error to the current
|
23
|
+
# messages
|
24
|
+
#
|
25
|
+
# @return [self]
|
26
|
+
#
|
27
|
+
# @api private
|
28
|
+
def set(error)
|
29
|
+
case error
|
30
|
+
when ActiveModel::Errors
|
31
|
+
__setobj__ error
|
32
|
+
when ROM::Model::ValidationError
|
33
|
+
__setobj__ error.errors
|
34
|
+
when nil
|
35
|
+
# do nothing
|
36
|
+
else
|
37
|
+
add(:base, "a database error prevented saving this form")
|
38
|
+
end
|
39
|
+
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
# Has the command succeeded?
|
44
|
+
#
|
45
|
+
# @return [Boolean]
|
46
|
+
#
|
47
|
+
# @api public
|
48
|
+
def success?
|
49
|
+
!present?
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/rom/rails/version.rb
CHANGED
data/rom-rails.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_runtime_dependency 'rom', '~> 0.
|
20
|
+
spec.add_runtime_dependency 'rom', '~> 0.7', '>= 0.7.0'
|
21
21
|
spec.add_runtime_dependency 'addressable', '~> 2.3'
|
22
22
|
spec.add_runtime_dependency 'charlatan', '~> 0.1'
|
23
23
|
spec.add_runtime_dependency 'virtus', '~> 1.0', '>= 1.0.5'
|
data/spec/dummy/Rakefile
CHANGED
@@ -4,3 +4,13 @@
|
|
4
4
|
require File.expand_path('../config/application', __FILE__)
|
5
5
|
|
6
6
|
Dummy::Application.load_tasks
|
7
|
+
|
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,7 +1,6 @@
|
|
1
1
|
require File.expand_path('../boot', __FILE__)
|
2
2
|
|
3
3
|
require "action_controller/railtie"
|
4
|
-
require "active_record/railtie"
|
5
4
|
|
6
5
|
Bundler.setup(:default, Rails.env)
|
7
6
|
|
@@ -12,5 +11,7 @@ require 'rspec-rails'
|
|
12
11
|
module Dummy
|
13
12
|
class Application < Rails::Application
|
14
13
|
config.assets.enabled = false
|
14
|
+
|
15
|
+
require 'rom/test_adapter'
|
15
16
|
end
|
16
17
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
ROM::Rails::Railtie.configure do |config|
|
2
|
+
db_config = ROM::Rails::ActiveRecord::Configuration.build(
|
3
|
+
Rails.application.config.database_configuration[Rails.env].symbolize_keys
|
4
|
+
.merge(root: Rails.root)
|
5
|
+
)
|
6
|
+
|
7
|
+
config.repositories[:default] = [:sql, db_config[:uri], db_config[:options]]
|
8
|
+
|
9
|
+
config.repositories[:test] = [:test_adapter, foo: :bar]
|
10
|
+
end
|
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
ROM::SQL.migration do
|
2
|
+
change do
|
3
3
|
create_table(:users) do |t|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
primary_key :id
|
5
|
+
String :name
|
6
|
+
String :email
|
7
|
+
DateTime :created_at
|
8
|
+
DateTime :updated_at
|
7
9
|
end
|
8
10
|
end
|
9
11
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ROM
|
2
|
+
module TestAdapter
|
3
|
+
class Relation < ROM::Relation
|
4
|
+
end
|
5
|
+
|
6
|
+
class Repository < ROM::Repository
|
7
|
+
include Equalizer.new(:args)
|
8
|
+
|
9
|
+
attr_reader :args, :datasets
|
10
|
+
|
11
|
+
def initialize(args)
|
12
|
+
@args = args
|
13
|
+
@datasets = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def dataset(name)
|
17
|
+
@datasets[name] = []
|
18
|
+
end
|
19
|
+
|
20
|
+
def dataset?(name)
|
21
|
+
datasets.key?(name)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
ROM.register_adapter(:test_adapter, ROM::TestAdapter)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'ROM initializer' do
|
4
|
+
it 'allows setting up a custom repository' do
|
5
|
+
repository = ROM::TestAdapter::Repository.new(foo: :bar)
|
6
|
+
relation = DummyRelation.new([])
|
7
|
+
|
8
|
+
expect(rom.repositories[:test]).to eql(repository)
|
9
|
+
expect(rom.relations.dummy).to eql(relation)
|
10
|
+
end
|
11
|
+
end
|
@@ -17,7 +17,7 @@ describe ROM::Generators::CommandsGenerator do
|
|
17
17
|
expect(destination_root).to have_structure {
|
18
18
|
directory 'app' do
|
19
19
|
directory 'commands' do
|
20
|
-
directory '
|
20
|
+
directory 'user_commands' do
|
21
21
|
file 'create.rb' do
|
22
22
|
contains <<-CONTENT.strip_heredoc
|
23
23
|
module UserCommands
|
@@ -68,13 +68,13 @@ describe ROM::Generators::CommandsGenerator do
|
|
68
68
|
specify "with given adapter" do
|
69
69
|
run_generator ['users', '--adapter=memory']
|
70
70
|
|
71
|
-
create = File.read(File.join(destination_root, 'app', 'commands', '
|
71
|
+
create = File.read(File.join(destination_root, 'app', 'commands', 'user_commands', 'create.rb'))
|
72
72
|
expect(create).to include("class Create < ROM::Commands::Create[:memory]")
|
73
73
|
|
74
|
-
update = File.read(File.join(destination_root, 'app', 'commands', '
|
74
|
+
update = File.read(File.join(destination_root, 'app', 'commands', 'user_commands', 'update.rb'))
|
75
75
|
expect(update).to include("class Update < ROM::Commands::Update[:memory]")
|
76
76
|
|
77
|
-
delete = File.read(File.join(destination_root, 'app', 'commands', '
|
77
|
+
delete = File.read(File.join(destination_root, 'app', 'commands', 'user_commands', 'delete.rb'))
|
78
78
|
expect(delete).to include("class Delete < ROM::Commands::Delete[:memory]")
|
79
79
|
end
|
80
80
|
end
|
@@ -19,8 +19,12 @@ describe ROM::Generators::RelationGenerator, type: :generator do
|
|
19
19
|
file 'users_relation.rb' do
|
20
20
|
contains <<-CONTENT.strip_heredoc
|
21
21
|
class UsersRelation < ROM::Relation[:#{default_adapter}]
|
22
|
+
# repository :default
|
23
|
+
|
22
24
|
dataset :users
|
23
25
|
|
26
|
+
register_as :users
|
27
|
+
|
24
28
|
# define your methods here ie:
|
25
29
|
#
|
26
30
|
# def all
|
@@ -40,4 +44,19 @@ describe ROM::Generators::RelationGenerator, type: :generator do
|
|
40
44
|
relation = File.read(File.join(destination_root, 'app', 'relations', 'users_relation.rb'))
|
41
45
|
expect(relation).to include("class UsersRelation < ROM::Relation[:memory]")
|
42
46
|
end
|
47
|
+
|
48
|
+
specify "with given repository" do
|
49
|
+
run_generator ['users', '--repository=remote']
|
50
|
+
|
51
|
+
relation = File.read(File.join(destination_root, 'app', 'relations', 'users_relation.rb'))
|
52
|
+
expect(relation).to include("repository :remote")
|
53
|
+
end
|
54
|
+
|
55
|
+
specify "with given registration" do
|
56
|
+
run_generator ['users', '--register=profiles']
|
57
|
+
|
58
|
+
relation = File.read(File.join(destination_root, 'app', 'relations', 'users_relation.rb'))
|
59
|
+
expect(relation).to include("register_as :profiles")
|
60
|
+
end
|
61
|
+
|
43
62
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -19,13 +19,21 @@ rescue LoadError
|
|
19
19
|
end
|
20
20
|
|
21
21
|
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
22
|
-
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
|
23
22
|
|
24
23
|
RSpec.configure do |config|
|
25
24
|
config.order = "random"
|
26
25
|
|
27
|
-
config.before(:
|
28
|
-
|
26
|
+
config.before(:suite) do
|
27
|
+
conn = ROM.env.repositories[:default].connection
|
28
|
+
|
29
|
+
DatabaseCleaner[:sequel, connection: conn].strategy = :transaction
|
30
|
+
DatabaseCleaner[:sequel, connection: conn].clean_with(:truncation)
|
31
|
+
end
|
32
|
+
|
33
|
+
config.around(:each) do |example|
|
34
|
+
conn = ROM.env.repositories[:default].connection
|
35
|
+
|
36
|
+
DatabaseCleaner[:sequel, connection: conn].cleaning { example.run }
|
29
37
|
end
|
30
38
|
end
|
31
39
|
|
data/spec/unit/form_spec.rb
CHANGED
@@ -202,13 +202,42 @@ describe 'Form' do
|
|
202
202
|
it "exposes an activemodel compatible error" do
|
203
203
|
errors = form.build({}).errors
|
204
204
|
|
205
|
-
expect(errors).to
|
206
|
-
|
207
|
-
)
|
205
|
+
expect(errors).to respond_to(:[])
|
206
|
+
expect(errors).to respond_to(:empty?)
|
207
|
+
expect(errors).to respond_to(:blank?)
|
208
208
|
|
209
209
|
expect(errors[:email]).to eq []
|
210
210
|
end
|
211
211
|
end
|
212
|
+
|
213
|
+
it "recovers from database errors" do
|
214
|
+
form = Class.new(ROM::Model::Form) do
|
215
|
+
commands users: :create
|
216
|
+
input do
|
217
|
+
set_model_name 'User'
|
218
|
+
|
219
|
+
attribute :email, String
|
220
|
+
end
|
221
|
+
|
222
|
+
def commit!(*args)
|
223
|
+
|
224
|
+
users.try {
|
225
|
+
raise ROM::SQL::ConstraintError.new(RuntimeError.new("duplicate key"))
|
226
|
+
}
|
227
|
+
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
result = form.build(email: 'test@example.com').save
|
232
|
+
|
233
|
+
expect(result).not_to be_success
|
234
|
+
|
235
|
+
expect(result.errors[:email]).to eq []
|
236
|
+
expect(result.errors[:base]).to eq ["a database error prevented saving this form"]
|
237
|
+
end
|
238
|
+
|
239
|
+
|
240
|
+
|
212
241
|
end
|
213
242
|
|
214
243
|
describe "#attributes" do
|
data/spec/unit/validator_spec.rb
CHANGED
@@ -7,6 +7,8 @@ describe 'Validation' do
|
|
7
7
|
Class.new {
|
8
8
|
include ROM::Model::Attributes
|
9
9
|
|
10
|
+
set_model_name 'User'
|
11
|
+
|
10
12
|
attribute :name, String
|
11
13
|
attribute :email, String
|
12
14
|
}
|
@@ -22,13 +24,13 @@ describe 'Validation' do
|
|
22
24
|
validates :email, uniqueness: true
|
23
25
|
|
24
26
|
def self.name
|
25
|
-
'
|
27
|
+
'User'
|
26
28
|
end
|
27
29
|
}
|
28
30
|
end
|
29
31
|
|
30
32
|
describe '#call' do
|
31
|
-
let(:attributes) {
|
33
|
+
let(:attributes) { user_attrs.new }
|
32
34
|
|
33
35
|
it 'raises validation error when attributes are not valid' do
|
34
36
|
expect { validator.call }.to raise_error(ROM::Model::ValidationError)
|
@@ -36,7 +38,7 @@ describe 'Validation' do
|
|
36
38
|
end
|
37
39
|
|
38
40
|
describe "#validate" do
|
39
|
-
let(:attributes) {
|
41
|
+
let(:attributes) { user_attrs.new }
|
40
42
|
|
41
43
|
it "sets errors when attributes are not valid" do
|
42
44
|
validator.validate
|
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.2
|
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-
|
11
|
+
date: 2015-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rom
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: '0.7'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.
|
22
|
+
version: 0.7.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.
|
29
|
+
version: '0.7'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.
|
32
|
+
version: 0.7.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: addressable
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,6 +178,7 @@ files:
|
|
178
178
|
- lib/rom/rails/model/attributes.rb
|
179
179
|
- lib/rom/rails/model/form.rb
|
180
180
|
- lib/rom/rails/model/form/class_interface.rb
|
181
|
+
- lib/rom/rails/model/form/error_proxy.rb
|
181
182
|
- lib/rom/rails/model/validator.rb
|
182
183
|
- lib/rom/rails/model/validator/uniqueness_validator.rb
|
183
184
|
- lib/rom/rails/railtie.rb
|
@@ -199,6 +200,7 @@ files:
|
|
199
200
|
- spec/dummy/app/mappers/users.rb
|
200
201
|
- spec/dummy/app/models/.keep
|
201
202
|
- spec/dummy/app/models/user.rb
|
203
|
+
- spec/dummy/app/relations/dummy_relation.rb
|
202
204
|
- spec/dummy/app/relations/tasks.rb
|
203
205
|
- spec/dummy/app/relations/users.rb
|
204
206
|
- spec/dummy/app/views/layouts/application.html.erb
|
@@ -220,6 +222,7 @@ files:
|
|
220
222
|
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
221
223
|
- spec/dummy/config/initializers/inflections.rb
|
222
224
|
- spec/dummy/config/initializers/mime_types.rb
|
225
|
+
- spec/dummy/config/initializers/rom.rb
|
223
226
|
- spec/dummy/config/initializers/secret_token.rb
|
224
227
|
- spec/dummy/config/initializers/session_store.rb
|
225
228
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
@@ -228,9 +231,8 @@ files:
|
|
228
231
|
- spec/dummy/db/migrate/20141110205016_add_users.rb
|
229
232
|
- spec/dummy/db/migrate/20150202194440_create_tasks.rb
|
230
233
|
- spec/dummy/db/migrate/20150403194906_create_tags.rb
|
231
|
-
- spec/dummy/db/schema.rb
|
232
|
-
- spec/dummy/db/seeds.rb
|
233
234
|
- spec/dummy/lib/assets/.keep
|
235
|
+
- spec/dummy/lib/rom/test_adapter.rb
|
234
236
|
- spec/dummy/lib/tasks/.keep
|
235
237
|
- spec/dummy/log/.keep
|
236
238
|
- spec/dummy/public/404.html
|
@@ -240,6 +242,7 @@ files:
|
|
240
242
|
- spec/dummy/public/robots.txt
|
241
243
|
- spec/dummy/spec/features/users_spec.rb
|
242
244
|
- spec/dummy/spec/integration/form_with_injected_commands_spec.rb
|
245
|
+
- spec/dummy/spec/integration/initializer_spec.rb
|
243
246
|
- spec/dummy/spec/integration/logger_spec.rb
|
244
247
|
- spec/dummy/spec/integration/new_user_form_spec.rb
|
245
248
|
- spec/dummy/spec/integration/user_attributes_spec.rb
|
@@ -296,6 +299,7 @@ test_files:
|
|
296
299
|
- spec/dummy/app/mappers/users.rb
|
297
300
|
- spec/dummy/app/models/.keep
|
298
301
|
- spec/dummy/app/models/user.rb
|
302
|
+
- spec/dummy/app/relations/dummy_relation.rb
|
299
303
|
- spec/dummy/app/relations/tasks.rb
|
300
304
|
- spec/dummy/app/relations/users.rb
|
301
305
|
- spec/dummy/app/views/layouts/application.html.erb
|
@@ -317,6 +321,7 @@ test_files:
|
|
317
321
|
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
318
322
|
- spec/dummy/config/initializers/inflections.rb
|
319
323
|
- spec/dummy/config/initializers/mime_types.rb
|
324
|
+
- spec/dummy/config/initializers/rom.rb
|
320
325
|
- spec/dummy/config/initializers/secret_token.rb
|
321
326
|
- spec/dummy/config/initializers/session_store.rb
|
322
327
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
@@ -325,9 +330,8 @@ test_files:
|
|
325
330
|
- spec/dummy/db/migrate/20141110205016_add_users.rb
|
326
331
|
- spec/dummy/db/migrate/20150202194440_create_tasks.rb
|
327
332
|
- spec/dummy/db/migrate/20150403194906_create_tags.rb
|
328
|
-
- spec/dummy/db/schema.rb
|
329
|
-
- spec/dummy/db/seeds.rb
|
330
333
|
- spec/dummy/lib/assets/.keep
|
334
|
+
- spec/dummy/lib/rom/test_adapter.rb
|
331
335
|
- spec/dummy/lib/tasks/.keep
|
332
336
|
- spec/dummy/log/.keep
|
333
337
|
- spec/dummy/public/404.html
|
@@ -337,6 +341,7 @@ test_files:
|
|
337
341
|
- spec/dummy/public/robots.txt
|
338
342
|
- spec/dummy/spec/features/users_spec.rb
|
339
343
|
- spec/dummy/spec/integration/form_with_injected_commands_spec.rb
|
344
|
+
- spec/dummy/spec/integration/initializer_spec.rb
|
340
345
|
- spec/dummy/spec/integration/logger_spec.rb
|
341
346
|
- spec/dummy/spec/integration/new_user_form_spec.rb
|
342
347
|
- spec/dummy/spec/integration/user_attributes_spec.rb
|
@@ -352,4 +357,3 @@ test_files:
|
|
352
357
|
- spec/spec_helper.rb
|
353
358
|
- spec/unit/form_spec.rb
|
354
359
|
- spec/unit/validator_spec.rb
|
355
|
-
has_rdoc:
|
data/spec/dummy/db/schema.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# This file is auto-generated from the current state of the database. Instead
|
3
|
-
# of editing this file, please use the migrations feature of Active Record to
|
4
|
-
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
-
#
|
6
|
-
# Note that this schema.rb definition is the authoritative source for your
|
7
|
-
# database schema. If you need to create the application database on another
|
8
|
-
# system, you should be using db:schema:load, not running all the migrations
|
9
|
-
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
-
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
-
#
|
12
|
-
# It's strongly recommended that you check this file into your version control system.
|
13
|
-
|
14
|
-
ActiveRecord::Schema.define(version: 20150403194906) do
|
15
|
-
|
16
|
-
create_table "tags", force: :cascade do |t|
|
17
|
-
t.string "name"
|
18
|
-
end
|
19
|
-
|
20
|
-
create_table "tasks", force: :cascade do |t|
|
21
|
-
t.string "title"
|
22
|
-
end
|
23
|
-
|
24
|
-
create_table "users", force: :cascade do |t|
|
25
|
-
t.string "name"
|
26
|
-
t.string "email"
|
27
|
-
t.datetime "created_at"
|
28
|
-
t.datetime "updated_at"
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
data/spec/dummy/db/seeds.rb
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
-
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
-
#
|
4
|
-
# Examples:
|
5
|
-
#
|
6
|
-
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
|
7
|
-
# Mayor.create(name: 'Emanuel', city: cities.first)
|