rom-rails 0.9.0 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/.travis.yml +1 -0
  4. data/CHANGELOG.md +14 -0
  5. data/Gemfile +8 -5
  6. data/lib/generators/rom/commands/templates/create.rb.erb +5 -7
  7. data/lib/generators/rom/commands/templates/update.rb.erb +5 -7
  8. data/lib/generators/rom/relation/templates/relation.rb.erb +6 -4
  9. data/lib/rom-rails.rb +0 -1
  10. data/lib/rom/rails/configuration.rb +0 -2
  11. data/lib/rom/rails/version.rb +1 -1
  12. data/rom-rails.gemspec +2 -4
  13. data/spec/dummy/app/commands/create_user.rb +10 -0
  14. data/spec/dummy/app/commands/update_user.rb +9 -0
  15. data/spec/dummy/app/controllers/users_controller.rb +12 -8
  16. data/spec/dummy/app/forms/user_form.rb +29 -9
  17. data/spec/dummy/app/mappers/task_mapper.rb +1 -1
  18. data/spec/dummy/app/mappers/user_mapper.rb +1 -1
  19. data/spec/dummy/app/models/user.rb +1 -1
  20. data/spec/dummy/app/relations/dummy_relation.rb +2 -1
  21. data/spec/dummy/app/relations/tasks.rb +2 -0
  22. data/spec/dummy/app/relations/users.rb +2 -0
  23. data/spec/dummy/lib/rom/test_adapter.rb +1 -1
  24. data/spec/features/users_spec.rb +1 -3
  25. data/spec/integration/activerecord_setup.rb +1 -1
  26. data/spec/integration/initializer_spec.rb +1 -3
  27. data/spec/integration/logger_spec.rb +1 -3
  28. data/spec/integration/user_commands_spec.rb +7 -7
  29. data/spec/integration/user_model_mapping_spec.rb +2 -4
  30. data/spec/lib/active_record/configuration_spec.rb +1 -2
  31. data/spec/lib/generators/commands_generator_spec.rb +7 -17
  32. data/spec/lib/generators/mapper_generator_spec.rb +1 -3
  33. data/spec/lib/generators/relation_generator_spec.rb +4 -8
  34. data/spec/lib/generators/repository_generator_spec.rb +1 -3
  35. data/spec/spec_helper.rb +1 -1
  36. metadata +12 -61
  37. data/lib/generators/rom/form/templates/base_form.rb.erb +0 -17
  38. data/lib/generators/rom/form/templates/edit_form.rb.erb +0 -20
  39. data/lib/generators/rom/form/templates/new_form.rb.erb +0 -20
  40. data/lib/generators/rom/form_generator.rb +0 -47
  41. data/lib/rom/rails/model/form.rb +0 -173
  42. data/lib/rom/rails/model/form/class_interface.rb +0 -457
  43. data/lib/rom/rails/model/form/error_proxy.rb +0 -53
  44. data/spec/dummy/app/forms/new_user_form.rb +0 -13
  45. data/spec/dummy/app/forms/update_user_form.rb +0 -11
  46. data/spec/integration/form_with_injected_commands_spec.rb +0 -37
  47. data/spec/integration/new_user_form_spec.rb +0 -19
  48. data/spec/lib/generators/form_generator_spec.rb +0 -140
  49. data/spec/unit/form_spec.rb +0 -366
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0e59843d440aaeb2a02a9d491e563a4d688fb0e
4
- data.tar.gz: a26ee36178717a151f1d7bdddc149ca5da8d7468
3
+ metadata.gz: 15ad5132adeb785fc04f97c8090c43adb48c41d0
4
+ data.tar.gz: fe847edfa4122b433dee45eea46b2c3795b9ccfd
5
5
  SHA512:
6
- metadata.gz: b485fd70f08ae8a61bf678cd9dad6125fb28389cd1ecd21fbb9378bb6960738044ed2398772a04fe34b0f02b5729ccd9bbb481c3c836e48ebf91b51251480027
7
- data.tar.gz: f16230e0d340682c8e3b32a2e6214d89049e80791ffd3de9ed610868db1cf87c4a39c6fcd974e726304a0d7cd7c41919f75876b9ad1435c76dfcb317a9b226c0
6
+ metadata.gz: 5348f013e4afbadb3d90b85391253d7ecd30737499b0c2a71ba3c330e643b87db80a109a0ebfe7986ec9375a09aa3e988e8b8e39ac3532099ebef5385ed67612
7
+ data.tar.gz: 70386c85f3322ddd242f5043eb3a37c8fe737b8065afbb5fcf578d4b46de90e5ef00316766533762d4e8e49f088b276eb4635737343c5a2b93dc0dc3d5047a0c
data/.rspec CHANGED
@@ -1 +1,3 @@
1
1
  --color
2
+ --order random
3
+ --require ./spec/spec_helper
@@ -10,6 +10,7 @@ rvm:
10
10
  - jruby-9.0.5.0
11
11
  - ruby-head
12
12
  env:
13
+ - RAILS_VERSION=5.1.0
13
14
  - RAILS_VERSION=5.0.0
14
15
  - RAILS_VERSION=4.2.0
15
16
  matrix:
@@ -1,3 +1,17 @@
1
+ ## HEAD
2
+
3
+ ### Changed
4
+
5
+ * Updated to work with ROM 4.0.beta (cflipse)
6
+
7
+ ### Removed
8
+
9
+ * remove ROM::Model::Form (cflipse)
10
+ * remove form generator (cflipse)
11
+ * remove deprecated `config.repositories` method (cflipse)
12
+ * No longer depends on `rom-model` gem (cflipse)
13
+ * No longer depends on `charlatan` gem (artofhuman)
14
+
1
15
  ## v0.9.0 2017-01-30
2
16
 
3
17
  ### Added
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- RAILS_VERSION = ENV.fetch("RAILS_VERSION", '5.0.0').freeze
5
+ RAILS_VERSION = ENV.fetch("RAILS_VERSION", '5.1.0').freeze
6
6
 
7
7
  %w(railties actionview actionpack activerecord).each do |name|
8
8
  gem name, "~> #{RAILS_VERSION}"
@@ -10,11 +10,14 @@ end
10
10
 
11
11
  gem 'sqlite3', platforms: [:mri, :rbx]
12
12
  gem 'byebug', platforms: :mri
13
- gem 'rom', github: 'rom-rb/rom', branch: 'master'
13
+
14
+ gem 'rom', git: 'https://github.com/rom-rb/rom', branch: 'master' do
15
+ gem 'rom-core'
16
+ gem 'rom-mapper'
17
+ gem 'rom-repository', group: :tools
18
+ end
19
+
14
20
  gem 'rom-sql', github: 'rom-rb/rom-sql', branch: 'master'
15
- gem 'rom-model', github: 'rom-rb/rom-model', branch: 'master'
16
- gem 'rom-repository', github: 'rom-rb/rom-repository', branch: 'master'
17
- gem 'rom-mapper', github: 'rom-rb/rom-mapper', branch: 'master'
18
21
 
19
22
  platforms :jruby do
20
23
  gem 'jdbc-sqlite3'
@@ -3,11 +3,9 @@ class Create<%= model_name %> < ROM::Commands::Create<%= "[:#{adapter}]" %>
3
3
  register_as :create
4
4
  result :one
5
5
 
6
- # Modify input data before committing it.
7
- # before :timestamp
8
-
9
- # def timestamp(tuple)
10
- # time = Time.current
11
- # tuple.merge(created_at: time, updated_at: time)
12
- # end
6
+ <% if adapter.to_sym == :sql -%>
7
+ # set Timestamp plugin
8
+ # use :timestamps
9
+ # timestamp :created_at, :updated_at
10
+ <% end -%>
13
11
  end
@@ -3,11 +3,9 @@ class Update<%= model_name %> < ROM::Commands::Update<%= "[:#{adapter}]" %>
3
3
  register_as :update
4
4
  result :one
5
5
 
6
- # Modify input data before committing it.
7
- # before :timestamp
8
-
9
- # def timestamp(tuple)
10
- # time = Time.current
11
- # tuple.merge(created_at: time)
12
- # end
6
+ <% if adapter.to_sym == :sql -%>
7
+ # set Timestamp plugin
8
+ # use :timestamps
9
+ # timestamp :updated_at
10
+ <% end -%>
13
11
  end
@@ -2,12 +2,14 @@ class <%= class_name %>Relation < ROM::Relation<%= "[:#{adapter}]" %>
2
2
  <% if gateway -%>
3
3
  gateway :<%= gateway %>
4
4
  <% else -%>
5
- # gateway :default
5
+ gateway :default
6
6
  <% end -%>
7
7
 
8
- dataset :<%= dataset %>
9
-
10
- register_as :<%= register_as %>
8
+ <% if register_as != dataset -%>
9
+ schema(:<%= dataset %>, as: :<%= register_as %>, infer: true)
10
+ <% else -%>
11
+ schema(:<%= dataset %>, infer: true)
12
+ <% end -%>
11
13
 
12
14
  # define your methods here ie:
13
15
  #
@@ -8,4 +8,3 @@ end
8
8
 
9
9
  require 'rom/rails/version'
10
10
  require 'rom/rails/railtie'
11
- require 'rom/rails/model/form'
@@ -13,8 +13,6 @@ module ROM
13
13
  config_accessor :auto_registration_paths do
14
14
  []
15
15
  end
16
-
17
- deprecate :repositories, :gateways
18
16
  end
19
17
  end
20
18
  end
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module Rails
3
- VERSION = '0.9.0'.freeze
3
+ VERSION = '1.0.0.beta1'.freeze
4
4
  end
5
5
  end
@@ -17,12 +17,10 @@ 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', '~> 3.0'
21
- spec.add_runtime_dependency 'rom-model', '~> 0.3'
20
+ spec.add_runtime_dependency 'rom', '~> 4.0.0.beta'
22
21
  spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
23
- spec.add_runtime_dependency 'dry-core', '~> 0.2', '>= 0.2.4'
22
+ spec.add_runtime_dependency 'dry-core', '~> 0.3'
24
23
  spec.add_runtime_dependency 'addressable', '~> 2.3'
25
- spec.add_runtime_dependency 'charlatan', '~> 0.1'
26
24
  spec.add_runtime_dependency 'railties', '>= 3.0', '< 6.0'
27
25
 
28
26
  spec.add_development_dependency "rom-repository"
@@ -0,0 +1,10 @@
1
+ class CreateUser < ROM::Commands::Create[:sql]
2
+ relation :users
3
+ register_as :create
4
+ result :one
5
+
6
+ use :timestamps
7
+
8
+ timestamp :created_at
9
+
10
+ end
@@ -0,0 +1,9 @@
1
+ class UpdateUser < ROM::Commands::Update[:sql]
2
+ relation :users
3
+ register_as :update
4
+ result :one
5
+
6
+ use :timestamps
7
+
8
+ timestamp :updated_at
9
+ end
@@ -4,23 +4,24 @@ class UsersController < ApplicationController
4
4
  end
5
5
 
6
6
  def index
7
- render :index, locals: { users: rom.relation(:users).as(:entity) }
7
+ render :index, locals: { users: rom.relations[:users].map_with(:user) }
8
8
  end
9
9
 
10
10
  def search
11
11
  render :index, locals: {
12
- users: rom.relation(:users).as(:entity).by_name(params[:name])
12
+ users: rom.relations[:users].map_with(:user).by_name(params[:name])
13
13
  }
14
14
  end
15
15
 
16
16
  def new
17
- render :new, locals: { user: NewUserForm.build }
17
+ render :new, locals: { user: UserForm.new }
18
18
  end
19
19
 
20
20
  def create
21
- user_form = NewUserForm.build(params[:user]).save
21
+ user_form = UserForm.new(params[:user].permit!)
22
22
 
23
- if user_form.success?
23
+ if user_form.valid?
24
+ rom.commands[:users].create.call(user_form.to_h)
24
25
  redirect_to :users
25
26
  else
26
27
  render :new, locals: { user: user_form }
@@ -28,15 +29,18 @@ class UsersController < ApplicationController
28
29
  end
29
30
 
30
31
  def edit
31
- user_form = UpdateUserForm.build({}, { id: params[:id] })
32
+ data = rom.relations[:users].where(id: params[:id]).one
33
+ user_form = UserForm.new(data)
32
34
 
33
35
  render :edit, locals: { user: user_form }
34
36
  end
35
37
 
36
38
  def update
37
- user_form = UpdateUserForm.build(params[:user], id: params[:id]).save
39
+ data = rom.relations[:users].where(id: params[:id]).one
40
+ user_form = UserForm.new(data).merge(params[:user].permit!)
38
41
 
39
- if user_form.success?
42
+ if user_form.valid?
43
+ rom.commands[:users].update.by_id(params[:id]).call(user_form.to_h)
40
44
  redirect_to :users
41
45
  else
42
46
  render :edit, locals: { user: user_form }
@@ -1,15 +1,35 @@
1
- class UserForm < ROM::Model::Form
2
- input do
3
- set_model_name 'User'
1
+ require 'active_model'
2
+ class UserForm
3
+ include ActiveModel::Model
4
+ include ActiveModel::Validations
4
5
 
5
- attribute :name, String
6
- attribute :email, String
6
+ attr_accessor :name, :email, :id
7
+
8
+ validates :name, :email, presence: true
9
+
10
+ def initialize(params = {})
11
+ @id = params[:id]
12
+ @name = params[:name]
13
+ @email = params[:email]
7
14
  end
8
15
 
9
- validations do
10
- relation :users
16
+ def to_h
17
+ { name: name, email: email }
18
+ end
11
19
 
12
- validates :name, :email, presence: true
13
- validates :email, uniqueness: true
20
+ def merge(input)
21
+ @name = input[:name]
22
+ @email = input[:email]
23
+
24
+ self
14
25
  end
26
+
27
+ def persisted?
28
+ !!id
29
+ end
30
+
31
+ def self.model_name
32
+ ActiveModel::Name.new(User)
33
+ end
34
+
15
35
  end
@@ -1,6 +1,6 @@
1
1
  class TaskMapper < ROM::Mapper
2
2
  relation :tasks
3
- register_as :entity
3
+ register_as :task
4
4
 
5
5
  model name: 'Task'
6
6
 
@@ -1,6 +1,6 @@
1
1
  class UserMapper < ROM::Mapper
2
2
  relation :users
3
- register_as :entity
3
+ register_as :user
4
4
 
5
5
  model User
6
6
 
@@ -1,5 +1,5 @@
1
1
  class User
2
- include Equalizer.new(:id, :name, :email)
2
+ include Dry::Equalizer(:id, :name, :email)
3
3
 
4
4
  attr_reader :id, :name, :email
5
5
 
@@ -1,4 +1,5 @@
1
1
  class DummyRelation < ROM::Relation[:test_adapter]
2
- register_as :dummy
3
2
  gateway :test
3
+
4
+ schema(:dummy, infer: true)
4
5
  end
@@ -1,4 +1,6 @@
1
1
  class Tasks < ROM::Relation[:sql]
2
+ schema(:tasks, infer: true)
3
+
2
4
  def by_id(id)
3
5
  where(id: id)
4
6
  end
@@ -1,4 +1,6 @@
1
1
  class Users < ROM::Relation[:sql]
2
+ schema(:users, infer: true)
3
+
2
4
  def by_id(id)
3
5
  where(id: id)
4
6
  end
@@ -5,7 +5,7 @@ module ROM
5
5
  end
6
6
 
7
7
  class Gateway < ROM::Gateway
8
- include Equalizer.new(:args)
8
+ include Dry::Equalizer(:args)
9
9
 
10
10
  attr_reader :args, :datasets
11
11
 
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- feature 'Users' do
1
+ RSpec.feature 'Users' do
4
2
  background do
5
3
  rom.relations.users.insert(name: 'Jane')
6
4
  rom.relations.users.insert(name: 'Joe')
@@ -1,4 +1,4 @@
1
- describe 'Connects to gateways using database.yml' do
1
+ RSpec.describe 'Connects to gateways using database.yml' do
2
2
  it 'works' do
3
3
  pending 'I have no idea how to load AR in isolation'
4
4
  raise 'database.yml must go'
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- describe 'ROM initializer' do
1
+ RSpec.describe 'ROM initializer' do
4
2
  it 'allows setting up a custom gateway' do
5
3
  gateway = ROM::TestAdapter::Gateway.new(foo: :bar)
6
4
  relation = DummyRelation.new([])
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- describe 'ROM logger' do
1
+ RSpec.describe 'ROM logger' do
4
2
  let(:rom) { ROM.env }
5
3
 
6
4
  it 'sets up rails logger for all gateways' do
@@ -1,14 +1,14 @@
1
- require 'spec_helper'
2
-
3
- describe 'User commands' do
4
- subject(:users) { rom.command(:users) }
1
+ RSpec.describe 'User commands' do
2
+ subject(:users) { rom.commands[:users] }
5
3
 
6
4
  describe 'delete' do
7
5
  it 'deletes record' do
8
- rom.relations.users.insert(name: 'Piotr', email: 'piotr@test.com')
9
- result = users.try { users.delete.by_name('Piotr') }
6
+ relation = rom.relations[:users]
7
+ relation.insert(name: 'Piotr', email: 'piotr@test.com')
10
8
 
11
- expect(result.error).to be(nil)
9
+ expect{
10
+ users.delete.by_name('Piotr').call
11
+ }.to change(relation, :count).by(-1)
12
12
  end
13
13
  end
14
14
  end
@@ -1,9 +1,7 @@
1
- require 'spec_helper'
2
-
3
- describe 'User model mapping' do
1
+ RSpec.describe 'User model mapping' do
4
2
  let(:rom) { ROM.env }
5
3
 
6
- let(:users) { rom.relation(:users).as(:entity) }
4
+ let(:users) { rom.relations[:users].map_with(:user) }
7
5
 
8
6
  before do
9
7
  rom.relations.users.insert(name: 'Piotr', email: 'piotr@test.com')
@@ -1,7 +1,6 @@
1
- require 'spec_helper'
2
1
  require 'rom/rails/active_record/configuration'
3
2
 
4
- describe ROM::Rails::ActiveRecord::Configuration do
3
+ RSpec.describe ROM::Rails::ActiveRecord::Configuration do
5
4
  let(:root) { Pathname.new('/path/to/app') }
6
5
 
7
6
  def uri_for(config)
@@ -1,8 +1,6 @@
1
- require 'spec_helper'
2
-
3
1
  require 'generators/rom/commands_generator'
4
2
 
5
- describe ROM::Generators::CommandsGenerator do
3
+ RSpec.describe ROM::Generators::CommandsGenerator do
6
4
  destination File.expand_path('../../../../tmp', __FILE__)
7
5
 
8
6
  before(:each) do
@@ -24,13 +22,9 @@ describe ROM::Generators::CommandsGenerator do
24
22
  register_as :create
25
23
  result :one
26
24
 
27
- # Modify input data before committing it.
28
- # before :timestamp
29
-
30
- # def timestamp(tuple)
31
- # time = Time.current
32
- # tuple.merge(created_at: time, updated_at: time)
33
- # end
25
+ # set Timestamp plugin
26
+ # use :timestamps
27
+ # timestamp :created_at, :updated_at
34
28
  end
35
29
  CONTENT
36
30
  end
@@ -42,13 +36,9 @@ describe ROM::Generators::CommandsGenerator do
42
36
  register_as :update
43
37
  result :one
44
38
 
45
- # Modify input data before committing it.
46
- # before :timestamp
47
-
48
- # def timestamp(tuple)
49
- # time = Time.current
50
- # tuple.merge(created_at: time)
51
- # end
39
+ # set Timestamp plugin
40
+ # use :timestamps
41
+ # timestamp :updated_at
52
42
  end
53
43
  CONTENT
54
44
  end