Sha256: 099c4c1edd7d73cc37fa6930465654a54e9b4a98ff873a03a2ff126307b2140a
Contents?: true
Size: 1.58 KB
Versions: 1
Compression:
Stored size: 1.58 KB
Contents
require 'spec_helper' describe Encore::Helpers::ControllerHelper do describe :process! do before do # Create a model spawn_model :User # Create a controller spawn_controller :UsersController do before_filter :fetch_user, only: [:update] define_method :create do @entity = UserEntity.new @entity.assign_attributes(params[:user], context: :create) process! @entity end define_method :update do @entity = UserEntity.new(@user) @entity.assign_attributes(params[:user], context: :update0) process! @entity end define_method :fetch_user do @user = User.find(params[:id]) end end # Create an entity spawn_entity :UserEntity do expose :name end run_migration do create_table(:users, force: true) do |t| t.string :name end end end let(:request) { ActionDispatch::TestRequest.new } let(:env) { request.env.tap { |e| e['action_dispatch.request.parameters'] = params } } context 'for create context' do let(:params) { { user: { name: 'H.E. Pennypacker' } } } let(:response) { UsersController.action(:create).call(env) } it { expect(response.first).to eql 201 } end context 'for update context' do before { User.create(name: 'Art Vandelay') } let(:params) { { id: 1, user: { name: 'H.E. Pennypacker' } } } let(:response) { UsersController.action(:update).call(env) } it { expect(response.first).to eql 200 } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
encore-0.0.3 | spec/encore/helpers/controller_helper_spec.rb |