rom-rails 0.3.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee83b2cd61d19031cd1d2cbe62ecec6fa0b925e2
4
- data.tar.gz: a5dd39a139c05983038283b5732f8f729a9d0519
3
+ metadata.gz: 3ed90e6218a40147b914444246e29f75156e839f
4
+ data.tar.gz: 19320a558924f23d5509e9e47ef0dffa01ff1ea1
5
5
  SHA512:
6
- metadata.gz: ad403f240fcd9d830749cae732f420dbc83c642655590b102bc2fcedd03fdd4397c29d1a128c32ba019044f75ba7d705b6326c3df76519decd176a524f0a5bd6
7
- data.tar.gz: b24db44eff800941024e20ce67c5558e09dd5aaf0448c47985181059b56d7f11fb652f2bbcf6daec6106c3b1528a1fb70a6cd5b1c19530201da18e7516897a7e
6
+ metadata.gz: f99f656233f503e2eac2edf435e90048cc1c0ed8923c41a63e8bc4bdae4f2ed6641090ee536f272ccbff80a9a3565b1594ed963e26aceb228d1ff1d80718d6db
7
+ data.tar.gz: 225c8450db829aa8620493c59091aec3cc1d007e41d000dfa54b283d1ad93ce11260697c1c406e699908a4b89ffcf978ed5daa4ffd9c11478f610c944fd8e903
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## v0.3.1 2015-04-04
2
+
3
+ ### Added
4
+
5
+ * `Form.mappings` which sets up auto-mapping command results (solnic)
6
+ * Form descendants can use `input` and `validations` blocks (cflipse)
7
+ * Form generators can generate a shared base form class for new/update forms (cflipse)
8
+
9
+ [Compare v0.3.0...v0.3.1](https://github.com/rom-rb/rom-rails/compare/v0.3.0...v0.3.1)
10
+
1
11
  ## v0.3.0 2015-03-22
2
12
 
3
13
  ### Added
data/Gemfile CHANGED
@@ -14,6 +14,7 @@ end
14
14
  group :test do
15
15
  gem 'rom', github: 'rom-rb/rom', branch: 'master'
16
16
  gem 'rom-sql', github: 'rom-rb/rom-sql', branch: 'master'
17
+ gem 'byebug', platforms: :mri
17
18
  gem 'rspec-rails', '~> 3.1'
18
19
  gem 'codeclimate-test-reporter', require: nil
19
20
  gem 'database_cleaner'
data/README.md CHANGED
@@ -31,8 +31,8 @@ Please report any issues in the main [rom-rb/rom](https://github.com/rom-rb/rom/
31
31
 
32
32
  You can read more about ROM and Rails on the official website:
33
33
 
34
- * [Introduction to ROM](http://rom-rb.org/introduction)
35
- * [Rails tutorial](http://rom-rb.org/tutorials/rails)
34
+ * [Introduction to ROM](http://rom-rb.org/introduction/)
35
+ * [Rails tutorial](http://rom-rb.org/tutorials/todo-app-with-rails/)
36
36
 
37
37
 
38
38
  ## Community
@@ -0,0 +1,17 @@
1
+ class <%= model_name %>Form < ROM::Model::Form
2
+
3
+ input do
4
+ set_model_name '<%= model_name %>'
5
+
6
+ # define always-present form input attributes
7
+ # attribute :name, String
8
+ end
9
+
10
+ validations do
11
+ relation :<%= relation %>
12
+
13
+ # Add invariant form validations
14
+ # validates :name, presence: true
15
+ end
16
+
17
+ end
@@ -1,9 +1,7 @@
1
- class Edit<%= model_name %>Form < ROM::Model::Form
1
+ class Edit<%= model_name %>Form < <%= model_name %>Form
2
2
  commands <%= relation %>: :update
3
3
 
4
4
  input do
5
- set_model_name '<%= model_name %>'
6
-
7
5
  # define form input attributes
8
6
  # attribute :name, String
9
7
 
@@ -11,8 +9,6 @@ class Edit<%= model_name %>Form < ROM::Model::Form
11
9
  end
12
10
 
13
11
  validations do
14
- relation :<%= relation %>
15
-
16
12
  # Add form validations
17
13
  # validates :name, presence: true
18
14
  end
@@ -1,9 +1,7 @@
1
- class New<%= model_name %>Form < ROM::Model::Form
1
+ class New<%= model_name %>Form < <%= model_name %>Form
2
2
  commands <%= relation %>: :create
3
3
 
4
4
  input do
5
- set_model_name '<%= model_name %>'
6
-
7
5
  # define form input attributes
8
6
  # attribute :name, String
9
7
 
@@ -11,8 +9,6 @@ class New<%= model_name %>Form < ROM::Model::Form
11
9
  end
12
10
 
13
11
  validations do
14
- relation :<%= relation %>
15
-
16
12
  # Add form validations
17
13
  # validates :name, presence: true
18
14
  end
@@ -5,16 +5,35 @@ module ROM
5
5
  class FormGenerator < Base
6
6
  class_option :command,
7
7
  banner: "--command=command",
8
- desc: "specify command to use", required: true
8
+ desc: "specify command to use"
9
9
 
10
- def create_command
11
- type = edit_or_new
10
+ def create_base_form
11
+ template "base_form.rb.erb",
12
+ File.join("app", "forms", "#{file_name.singularize}_form.rb")
13
+ end
14
+
15
+ def create_new
16
+ create(:new) if create_new_form?
17
+ end
18
+
19
+ def create_edit
20
+ create(:edit) if create_edit_form?
21
+ end
22
+
23
+ private
12
24
 
25
+ def create(type)
13
26
  template "#{type}_form.rb.erb",
14
27
  File.join("app", "forms", "#{type}_#{file_name.singularize}_form.rb")
15
28
  end
16
29
 
17
- private
30
+ def create_new_form?
31
+ options[:command].blank? || %w(new create).include?(options[:command].to_s.downcase)
32
+ end
33
+
34
+ def create_edit_form?
35
+ options[:command].blank? || %w(edit update).include?(options[:command].to_s.downcase)
36
+ end
18
37
 
19
38
  def model_name
20
39
  class_name.singularize.camelcase
@@ -24,16 +43,6 @@ module ROM
24
43
  class_name.pluralize.underscore
25
44
  end
26
45
 
27
- def edit_or_new
28
- case options[:command].downcase
29
- when 'edit', 'update'
30
- :edit
31
- when 'new', 'create'
32
- :new
33
- else
34
- raise "Unknown command"
35
- end
36
- end
37
46
  end
38
47
  end
39
48
  end
@@ -48,7 +48,7 @@ module ROM
48
48
  extend ROM::ClassMacros
49
49
  extend Form::ClassInterface
50
50
 
51
- defines :relation
51
+ defines :relation, :mappings
52
52
 
53
53
  # Return raw params received from the request
54
54
  #
@@ -70,28 +70,14 @@ module ROM
70
70
  # @api private
71
71
  attr_reader :injectible_commands
72
72
 
73
- # input block stored to be used in inherited hook
74
- #
75
- # @return [Proc]
76
- #
77
- # @api private
78
- attr_reader :input_block
79
-
80
- # validation block stored to be used in inherited hook
81
- #
82
- # @return [Proc]
83
- #
84
- # @api private
85
- attr_reader :validations_block
86
-
87
73
  # Copy input attributes, validator and model to the descendant
88
74
  #
89
75
  # @api private
90
76
  def inherited(klass)
91
77
  klass.inject_commands_for(*injectible_commands) if injectible_commands
92
78
  klass.commands(*self_commands) if self_commands
93
- klass.input(readers: false, &input_block) if input_block
94
- klass.validations(&validations_block) if validations_block
79
+ input_blocks.each{|block| klass.input(readers: false, &block) }
80
+ validation_blocks.each{|block| klass.validations(&block) }
95
81
  super
96
82
  end
97
83
 
@@ -234,11 +220,35 @@ module ROM
234
220
  #
235
221
  # @api public
236
222
  def build(input = {}, options = {})
237
- new(input, options.merge(command_registry))
223
+ commands =
224
+ if mappings
225
+ command_registry.each_with_object({}) { |(relation, registry), h|
226
+ mapper = mappings[relation]
227
+
228
+ h[relation] =
229
+ if mapper
230
+ registry.as(mapper)
231
+ else
232
+ registry
233
+ end
234
+ }
235
+ else
236
+ command_registry
237
+ end
238
+ new(input, options.merge(commands))
238
239
  end
239
240
 
240
241
  private
241
242
 
243
+ # retrieve a list of reserved method names
244
+ #
245
+ # @return [Array<Symbol>]
246
+ #
247
+ # @api private
248
+ def reserved_attributes
249
+ ROM::Model::Form.public_instance_methods
250
+ end
251
+
242
252
  # @return [Hash<Symbol=>ROM::CommandRegistry>]
243
253
  #
244
254
  # @api private
@@ -246,18 +256,39 @@ module ROM
246
256
  @command_registry ||= setup_command_registry
247
257
  end
248
258
 
259
+ # input block stored to be used in inherited hook
260
+ #
261
+ # @return [Proc]
262
+ #
263
+ # @api private
264
+ def input_blocks
265
+ @input_blocks ||= []
266
+ end
267
+
268
+ # validation blocks stored to be used in inherited hook
269
+ #
270
+ # @return [Proc]
271
+ #
272
+ # @api private
273
+ def validation_blocks
274
+ @validation_blocks ||= []
275
+ end
276
+
249
277
  # Create attribute handler class
250
278
  #
251
279
  # @return [Class]
252
280
  #
253
281
  # @api private
254
282
  def define_attributes!(block)
255
- @input_block = block
283
+ input_blocks << block
256
284
  @attributes = ClassBuilder.new(name: "#{name}::Attributes", parent: Object).call { |klass|
257
285
  klass.send(:include, ROM::Model::Attributes)
258
286
  }
259
- @attributes.class_eval(&block)
260
- const_set(:Attributes, @attributes)
287
+ input_blocks.each do |input_block|
288
+ @attributes.class_eval(&input_block)
289
+ end
290
+
291
+ update_const(:Attributes, @attributes)
261
292
  end
262
293
 
263
294
  # Define attribute readers for the form
@@ -270,8 +301,9 @@ module ROM
270
301
  #
271
302
  # @api private
272
303
  def define_attribute_readers!
304
+ reserved = reserved_attributes
273
305
  @attributes.attribute_set.each do |attribute|
274
- if public_instance_methods.include?(attribute.name)
306
+ if reserved.include?(attribute.name)
275
307
  raise(
276
308
  ArgumentError,
277
309
  "#{attribute.name} attribute is in conflict with #{self}##{attribute.name}"
@@ -313,7 +345,8 @@ module ROM
313
345
  RUBY
314
346
  }
315
347
  key.each { |name| @model.attribute(name) }
316
- const_set(:Model, @model)
348
+
349
+ update_const(:Model, @model)
317
350
  end
318
351
 
319
352
  # Define attribute validator class
@@ -322,12 +355,12 @@ module ROM
322
355
  #
323
356
  # @api private
324
357
  def define_validator!(block)
325
- @validations_block = block
358
+ validation_blocks << block
326
359
  @validator = ClassBuilder.new(name: "#{name}::Validator", parent: Object).call { |klass|
327
360
  klass.send(:include, ROM::Model::Validator)
328
361
  }
329
- @validator.class_eval(&block)
330
- const_set(:Validator, @validator)
362
+ validation_blocks.each{|validation| @validator.class_eval(&validation) }
363
+ update_const(:Validator, @validator)
331
364
  end
332
365
 
333
366
  # Shortcut to global ROM env
@@ -362,7 +395,15 @@ module ROM
362
395
  if self_commands
363
396
  self_commands.each do |rel_name, name|
364
397
  command = build_command(name, rel_name)
365
- commands[rel_name] = CommandRegistry.new(name => command)
398
+ elements = { name => command }
399
+ options =
400
+ if rom.mappers.key?(rel_name)
401
+ { mappers: rom.mappers[rel_name] }
402
+ else
403
+ {}
404
+ end
405
+
406
+ commands[rel_name] = CommandRegistry.new(elements, options)
366
407
  end
367
408
  end
368
409
 
@@ -395,6 +436,19 @@ module ROM
395
436
 
396
437
  klass.build(relation)
397
438
  end
439
+
440
+
441
+ # Silently update a constant, replacing any existing definition without
442
+ # warning
443
+ #
444
+ # @param [Symbol] name the name of the constant
445
+ # @param [Class] klass class to assign
446
+ #
447
+ # @api private
448
+ def update_const(name, klass)
449
+ remove_const(name) if const_defined?(name, false)
450
+ const_set(name, klass)
451
+ end
398
452
  end
399
453
  end
400
454
  end
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module Rails
3
- VERSION = '0.3.0'.freeze
3
+ VERSION = '0.3.1'.freeze
4
4
  end
5
5
  end
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.6.0'
20
+ spec.add_runtime_dependency 'rom', '~> 0.6.0', '>= 0.6.1'
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'
@@ -4,12 +4,12 @@ class UsersController < ApplicationController
4
4
  end
5
5
 
6
6
  def index
7
- render :index, locals: { users: rom.relation(:users).as(:users) }
7
+ render :index, locals: { users: rom.relation(:users).as(:entity) }
8
8
  end
9
9
 
10
10
  def search
11
11
  render :index, locals: {
12
- users: rom.relation(:users).as(:users).by_name(params[:name])
12
+ users: rom.relation(:users).as(:entity).by_name(params[:name])
13
13
  }
14
14
  end
15
15
 
@@ -1,7 +1,11 @@
1
1
  class NewUserForm < UserForm
2
2
  commands users: :create
3
3
 
4
- attributes.timestamps(:created_at)
4
+ mappings users: :entity
5
+
6
+ input do
7
+ timestamps(:created_at)
8
+ end
5
9
 
6
10
  def commit!
7
11
  users.try { users.create.call(attributes) }
@@ -1,7 +1,9 @@
1
1
  class UpdateUserForm < UserForm
2
2
  commands users: :update
3
3
 
4
- attributes.timestamps(:updated_at)
4
+ input do
5
+ timestamps(:updated_at)
6
+ end
5
7
 
6
8
  def commit!
7
9
  users.try { users.update.by_id(id).set(attributes) }
@@ -0,0 +1,9 @@
1
+ class TaskMapper < ROM::Mapper
2
+ relation :tasks
3
+ register_as :entity
4
+
5
+ model name: 'Task'
6
+
7
+ attribute :id
8
+ attribute :title
9
+ end
@@ -1,8 +1,10 @@
1
1
  class UserMapper < ROM::Mapper
2
2
  relation :users
3
+ register_as :entity
3
4
 
4
5
  model User
5
6
 
6
7
  attribute :id
7
8
  attribute :name
9
+ attribute :email
8
10
  end
@@ -1,9 +1,9 @@
1
1
  class User
2
- include Equalizer.new(:id, :name)
2
+ include Equalizer.new(:id, :name, :email)
3
3
 
4
- attr_reader :id, :name
4
+ attr_reader :id, :name, :email
5
5
 
6
6
  def initialize(attrs)
7
- @id, @name = attrs.values_at(:id, :name)
7
+ @id, @name, @email = attrs.values_at(:id, :name, :email)
8
8
  end
9
9
  end
@@ -0,0 +1,7 @@
1
+ class CreateTags < ActiveRecord::Migration
2
+ def change
3
+ create_table :tags do |t|
4
+ t.string :name
5
+ end
6
+ end
7
+ end
@@ -11,7 +11,11 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20150202194440) do
14
+ ActiveRecord::Schema.define(version: 20150403194906) do
15
+
16
+ create_table "tags", force: :cascade do |t|
17
+ t.string "name"
18
+ end
15
19
 
16
20
  create_table "tasks", force: :cascade do |t|
17
21
  t.string "title"
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Form with injected commands' do
4
+ subject(:form) { form_class.build(params) }
5
+
6
+ let(:params) { { title: 'Task one' } }
7
+
8
+ let(:form_class) do
9
+ Class.new(ROM::Model::Form) do
10
+ commands users: :create, tags: :create
11
+
12
+ inject_commands_for :tasks
13
+
14
+ mappings tasks: :entity
15
+
16
+ input do
17
+ set_model_name 'Task'
18
+
19
+ attribute :title
20
+ end
21
+
22
+ def commit!
23
+ tasks.create[attributes]
24
+ end
25
+ end
26
+ end
27
+
28
+ it 'auto-maps result using injected commands' do
29
+ form.save
30
+
31
+ value = form.result
32
+
33
+ expect(value).to be_a(Task)
34
+ expect(value.id).to_not be(nil)
35
+ expect(value.title).to eql('Task one')
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe NewUserForm do
4
+ subject(:form) { NewUserForm.build(params) }
5
+
6
+ let(:params) do
7
+ { name: 'Jane', email: 'jane@doe.org' }
8
+ end
9
+
10
+ describe '#save' do
11
+ it 'persists attributes and auto-map result to entity object' do
12
+ form.save
13
+
14
+ user = form.result.value
15
+
16
+ expect(user).to eql(User.new(id: 1, name: 'Jane', email: 'jane@doe.org'))
17
+ end
18
+ end
19
+ end
@@ -3,14 +3,14 @@ require 'spec_helper'
3
3
  describe 'User model mapping' do
4
4
  let(:rom) { ROM.env }
5
5
 
6
- let(:users) { rom.relation(:users).as(:users) }
6
+ let(:users) { rom.relation(:users).as(:entity) }
7
7
 
8
8
  before do
9
9
  rom.relations.users.insert(name: 'Piotr', email: 'piotr@test.com')
10
10
  end
11
11
 
12
12
  it 'works' do
13
- piotr = User.new(id: 1, name: 'Piotr')
13
+ piotr = User.new(id: 1, name: 'Piotr', email: 'piotr@test.com')
14
14
 
15
15
  expect(users.by_name('Piotr').to_a).to eql([piotr])
16
16
  end
@@ -9,20 +9,49 @@ describe ROM::Generators::FormGenerator do
9
9
  prepare_destination
10
10
  end
11
11
 
12
- specify "a create form" do
13
- run_generator ['users', '--command=create']
14
-
15
- expect(destination_root).to have_structure {
16
- directory 'app' do
17
- directory 'forms' do
18
- file 'new_user_form.rb' do
19
- contains <<-CONTENT.strip_heredoc
20
- class NewUserForm < ROM::Model::Form
21
- commands users: :create
12
+ shared_examples_for "generates a base user form" do
13
+ it "populates a base form file" do
14
+ expect(destination_root).to have_structure {
15
+ directory 'app' do
16
+ directory 'forms' do
17
+ file 'user_form.rb' do
18
+ contains <<-CONTENT.strip_heredoc
19
+ class UserForm < ROM::Model::Form
22
20
 
23
21
  input do
24
22
  set_model_name 'User'
25
23
 
24
+ # define always-present form input attributes
25
+ # attribute :name, String
26
+ end
27
+
28
+ validations do
29
+ relation :users
30
+
31
+ # Add invariant form validations
32
+ # validates :name, presence: true
33
+ end
34
+
35
+ end
36
+ CONTENT
37
+ end
38
+ end
39
+ end
40
+ }
41
+ end
42
+ end
43
+
44
+ shared_examples_for "generates a create user form" do
45
+ it "populates a create form file" do
46
+ expect(destination_root).to have_structure {
47
+ directory 'app' do
48
+ directory 'forms' do
49
+ file 'new_user_form.rb' do
50
+ contains <<-CONTENT.strip_heredoc
51
+ class NewUserForm < UserForm
52
+ commands users: :create
53
+
54
+ input do
26
55
  # define form input attributes
27
56
  # attribute :name, String
28
57
 
@@ -30,8 +59,6 @@ describe ROM::Generators::FormGenerator do
30
59
  end
31
60
 
32
61
  validations do
33
- relation :users
34
-
35
62
  # Add form validations
36
63
  # validates :name, presence: true
37
64
  end
@@ -41,27 +68,26 @@ describe ROM::Generators::FormGenerator do
41
68
  end
42
69
 
43
70
  end
44
- CONTENT
71
+ CONTENT
72
+ end
45
73
  end
46
74
  end
47
- end
48
- }
75
+ }
76
+ end
49
77
  end
50
78
 
51
- specify "an edit form" do
52
- run_generator ['users', '--command=update']
79
+ shared_examples_for "generates an edit user form" do
53
80
 
54
- expect(destination_root).to have_structure {
55
- directory 'app' do
56
- directory 'forms' do
57
- file 'edit_user_form.rb' do
58
- contains <<-CONTENT.strip_heredoc
59
- class EditUserForm < ROM::Model::Form
81
+ it "populates a edit form file" do
82
+ expect(destination_root).to have_structure {
83
+ directory 'app' do
84
+ directory 'forms' do
85
+ file 'edit_user_form.rb' do
86
+ contains <<-CONTENT.strip_heredoc
87
+ class EditUserForm < UserForm
60
88
  commands users: :update
61
89
 
62
90
  input do
63
- set_model_name 'User'
64
-
65
91
  # define form input attributes
66
92
  # attribute :name, String
67
93
 
@@ -69,8 +95,6 @@ describe ROM::Generators::FormGenerator do
69
95
  end
70
96
 
71
97
  validations do
72
- relation :users
73
-
74
98
  # Add form validations
75
99
  # validates :name, presence: true
76
100
  end
@@ -80,10 +104,40 @@ describe ROM::Generators::FormGenerator do
80
104
  end
81
105
 
82
106
  end
83
- CONTENT
107
+ CONTENT
108
+ end
84
109
  end
85
110
  end
86
- end
87
- }
111
+ }
112
+ end
113
+ end
114
+
115
+ describe "rom:form users" do
116
+ before do
117
+ run_generator ['users']
118
+ end
119
+
120
+ it_should_behave_like "generates a create user form"
121
+ it_should_behave_like "generates an edit user form"
88
122
  end
123
+
124
+ describe "rom:form users --command=create" do
125
+ before do
126
+ run_generator ['users', '--command=create']
127
+ end
128
+
129
+ it_should_behave_like "generates a base user form"
130
+ it_should_behave_like "generates a create user form"
131
+ end
132
+
133
+ describe "rom:form users --command=update" do
134
+ before do
135
+ run_generator ['users', '--command=update']
136
+ end
137
+
138
+ it_should_behave_like "generates a base user form"
139
+ it_should_behave_like "generates an edit user form"
140
+ end
141
+
142
+
89
143
  end
data/spec/spec_helper.rb CHANGED
@@ -13,6 +13,11 @@ require 'database_cleaner'
13
13
  require 'capybara/rails'
14
14
  require 'generator_spec'
15
15
 
16
+ begin
17
+ require 'byebug'
18
+ rescue LoadError
19
+ end
20
+
16
21
  Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
17
22
  ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
18
23
 
@@ -67,7 +67,7 @@ describe 'Form' do
67
67
  expect(form_object).to be_success
68
68
  expect(rom.relations.users.first).to include(name: 'Jane')
69
69
 
70
- expect(form_object.tasks).to be(rom.command(:tasks))
70
+ expect(form_object.tasks).to_not be(nil)
71
71
  end
72
72
  end
73
73
 
@@ -286,6 +286,23 @@ describe 'Form' do
286
286
  expect(child_form.attributes).to_not be(form.attributes)
287
287
  end
288
288
 
289
+ it 'expands input' do
290
+ child_form = Class.new(form) do
291
+ def self.name
292
+ "NewUserForm"
293
+ end
294
+
295
+ input do
296
+ attribute :login, String
297
+ end
298
+ end
299
+
300
+ expect(child_form.attributes.attribute_set[:login]).to_not be(nil)
301
+ expect(child_form.attributes.attribute_set[:email]).to_not be(nil)
302
+
303
+ expect(child_form.attributes).to_not be(form.attributes)
304
+ end
305
+
289
306
  it 'copies model' do
290
307
  expect(child_form.model.attribute_set[:email]).to_not be(nil)
291
308
  expect(child_form.model).to_not be(form.model)
@@ -297,5 +314,33 @@ describe 'Form' do
297
314
  )
298
315
  expect(child_form.validator).to_not be(form.validator)
299
316
  end
317
+
318
+ it "expands existing validators" do
319
+ child_form = Class.new(form) do
320
+ def self.name
321
+ "NewUserForm"
322
+ end
323
+
324
+ input do
325
+ attribute :login, String
326
+ end
327
+
328
+ validations do
329
+ validates :login, length: { minimum: 4 }
330
+ end
331
+ end
332
+
333
+ expect(child_form.validator.validators.first).to be_instance_of(
334
+ ActiveModel::Validations::PresenceValidator
335
+ )
336
+
337
+ expect(child_form.validator.validators.last).to be_instance_of(
338
+ ActiveModel::Validations::LengthValidator
339
+ )
340
+
341
+ expect(child_form.validator).to_not be(form.validator)
342
+ end
343
+
344
+
300
345
  end
301
346
  end
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.0
4
+ version: 0.3.1
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-03-22 00:00:00.000000000 Z
11
+ date: 2015-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rom
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.6.0
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.6.1
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
29
  version: 0.6.0
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.6.1
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: addressable
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -155,6 +161,7 @@ files:
155
161
  - lib/generators/rom/commands/templates/delete.rb.erb
156
162
  - lib/generators/rom/commands/templates/update.rb.erb
157
163
  - lib/generators/rom/commands_generator.rb
164
+ - lib/generators/rom/form/templates/base_form.rb.erb
158
165
  - lib/generators/rom/form/templates/edit_form.rb.erb
159
166
  - lib/generators/rom/form/templates/new_form.rb.erb
160
167
  - lib/generators/rom/form_generator.rb
@@ -188,6 +195,7 @@ files:
188
195
  - spec/dummy/app/forms/user_form.rb
189
196
  - spec/dummy/app/helpers/application_helper.rb
190
197
  - spec/dummy/app/mailers/.keep
198
+ - spec/dummy/app/mappers/tasks.rb
191
199
  - spec/dummy/app/mappers/users.rb
192
200
  - spec/dummy/app/models/.keep
193
201
  - spec/dummy/app/models/user.rb
@@ -219,6 +227,7 @@ files:
219
227
  - spec/dummy/config/routes.rb
220
228
  - spec/dummy/db/migrate/20141110205016_add_users.rb
221
229
  - spec/dummy/db/migrate/20150202194440_create_tasks.rb
230
+ - spec/dummy/db/migrate/20150403194906_create_tags.rb
222
231
  - spec/dummy/db/schema.rb
223
232
  - spec/dummy/db/seeds.rb
224
233
  - spec/dummy/lib/assets/.keep
@@ -230,7 +239,9 @@ files:
230
239
  - spec/dummy/public/favicon.ico
231
240
  - spec/dummy/public/robots.txt
232
241
  - spec/dummy/spec/features/users_spec.rb
242
+ - spec/dummy/spec/integration/form_with_injected_commands_spec.rb
233
243
  - spec/dummy/spec/integration/logger_spec.rb
244
+ - spec/dummy/spec/integration/new_user_form_spec.rb
234
245
  - spec/dummy/spec/integration/user_attributes_spec.rb
235
246
  - spec/dummy/spec/integration/user_commands_spec.rb
236
247
  - spec/dummy/spec/integration/user_model_mapping_spec.rb
@@ -281,6 +292,7 @@ test_files:
281
292
  - spec/dummy/app/forms/user_form.rb
282
293
  - spec/dummy/app/helpers/application_helper.rb
283
294
  - spec/dummy/app/mailers/.keep
295
+ - spec/dummy/app/mappers/tasks.rb
284
296
  - spec/dummy/app/mappers/users.rb
285
297
  - spec/dummy/app/models/.keep
286
298
  - spec/dummy/app/models/user.rb
@@ -312,6 +324,7 @@ test_files:
312
324
  - spec/dummy/config/routes.rb
313
325
  - spec/dummy/db/migrate/20141110205016_add_users.rb
314
326
  - spec/dummy/db/migrate/20150202194440_create_tasks.rb
327
+ - spec/dummy/db/migrate/20150403194906_create_tags.rb
315
328
  - spec/dummy/db/schema.rb
316
329
  - spec/dummy/db/seeds.rb
317
330
  - spec/dummy/lib/assets/.keep
@@ -323,7 +336,9 @@ test_files:
323
336
  - spec/dummy/public/favicon.ico
324
337
  - spec/dummy/public/robots.txt
325
338
  - spec/dummy/spec/features/users_spec.rb
339
+ - spec/dummy/spec/integration/form_with_injected_commands_spec.rb
326
340
  - spec/dummy/spec/integration/logger_spec.rb
341
+ - spec/dummy/spec/integration/new_user_form_spec.rb
327
342
  - spec/dummy/spec/integration/user_attributes_spec.rb
328
343
  - spec/dummy/spec/integration/user_commands_spec.rb
329
344
  - spec/dummy/spec/integration/user_model_mapping_spec.rb
@@ -337,3 +352,4 @@ test_files:
337
352
  - spec/spec_helper.rb
338
353
  - spec/unit/form_spec.rb
339
354
  - spec/unit/validator_spec.rb
355
+ has_rdoc: