simple_form_class 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +28 -0
- data/.travis.yml +19 -0
- data/Gemfile +27 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +45 -0
- data/lib/simple_form_class.rb +10 -0
- data/lib/simple_form_class/base.rb +212 -0
- data/lib/simple_form_class/version.rb +3 -0
- data/simple_form_class.gemspec +33 -0
- data/test/.gitkeep +0 -0
- data/test/dummy/.gitignore +15 -0
- data/test/dummy/Gemfile +38 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/images/rails.png +0 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/javascripts/orders.js.coffee +3 -0
- data/test/dummy/app/assets/javascripts/products.js.coffee +3 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/assets/stylesheets/orders.css.scss +3 -0
- data/test/dummy/app/assets/stylesheets/products.css.scss +3 -0
- data/test/dummy/app/assets/stylesheets/scaffolds.css.scss +69 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/orders_controller.rb +83 -0
- data/test/dummy/app/controllers/products_controller.rb +83 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/orders_helper.rb +2 -0
- data/test/dummy/app/helpers/products_helper.rb +2 -0
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/models/order.rb +2 -0
- data/test/dummy/app/models/product.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/orders/_form.html.erb +29 -0
- data/test/dummy/app/views/orders/edit.html.erb +6 -0
- data/test/dummy/app/views/orders/index.html.erb +27 -0
- data/test/dummy/app/views/orders/new.html.erb +5 -0
- data/test/dummy/app/views/orders/show.html.erb +20 -0
- data/test/dummy/app/views/products/_form.html.erb +25 -0
- data/test/dummy/app/views/products/edit.html.erb +6 -0
- data/test/dummy/app/views/products/index.html.erb +25 -0
- data/test/dummy/app/views/products/new.html.erb +5 -0
- data/test/dummy/app/views/products/show.html.erb +15 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +64 -0
- data/test/dummy/config/boot.rb +6 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +24 -0
- data/test/dummy/config/environments/production.rb +55 -0
- data/test/dummy/config/environments/test.rb +25 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +64 -0
- data/test/dummy/db/migrate/20130420130732_create_products.rb +10 -0
- data/test/dummy/db/migrate/20130420130801_create_orders.rb +11 -0
- data/test/dummy/db/schema.rb +31 -0
- data/test/dummy/db/seeds.rb +7 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/lib/tasks/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/index.html +241 -0
- data/test/dummy/public/robots.txt +5 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/fixtures/.gitkeep +0 -0
- data/test/dummy/test/fixtures/orders.yml +11 -0
- data/test/dummy/test/fixtures/products.yml +9 -0
- data/test/dummy/test/functional/.gitkeep +0 -0
- data/test/dummy/test/functional/orders_controller_test.rb +49 -0
- data/test/dummy/test/functional/products_controller_test.rb +49 -0
- data/test/dummy/test/integration/.gitkeep +0 -0
- data/test/dummy/test/performance/browsing_test.rb +12 -0
- data/test/dummy/test/test_helper.rb +13 -0
- data/test/dummy/test/unit/.gitkeep +0 -0
- data/test/dummy/test/unit/helpers/orders_helper_test.rb +4 -0
- data/test/dummy/test/unit/helpers/products_helper_test.rb +4 -0
- data/test/dummy/test/unit/order_test.rb +7 -0
- data/test/dummy/test/unit/product_test.rb +7 -0
- data/test/dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/test/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/test/dummy/vendor/plugins/.gitkeep +0 -0
- data/test/support/dummy_app.rb +86 -0
- data/test/test_helper.rb +66 -0
- data/test/unit/base_test.rb +210 -0
- metadata +405 -0
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
File without changes
|
File without changes
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class OrdersControllerTest < ActionController::TestCase
|
4
|
+
setup do
|
5
|
+
@order = orders(:one)
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should get index" do
|
9
|
+
get :index
|
10
|
+
assert_response :success
|
11
|
+
assert_not_nil assigns(:orders)
|
12
|
+
end
|
13
|
+
|
14
|
+
test "should get new" do
|
15
|
+
get :new
|
16
|
+
assert_response :success
|
17
|
+
end
|
18
|
+
|
19
|
+
test "should create order" do
|
20
|
+
assert_difference('Order.count') do
|
21
|
+
post :create, order: { order_number: @order.order_number, price: @order.price, product_id: @order.product_id }
|
22
|
+
end
|
23
|
+
|
24
|
+
assert_redirected_to order_path(assigns(:order))
|
25
|
+
end
|
26
|
+
|
27
|
+
test "should show order" do
|
28
|
+
get :show, id: @order
|
29
|
+
assert_response :success
|
30
|
+
end
|
31
|
+
|
32
|
+
test "should get edit" do
|
33
|
+
get :edit, id: @order
|
34
|
+
assert_response :success
|
35
|
+
end
|
36
|
+
|
37
|
+
test "should update order" do
|
38
|
+
put :update, id: @order, order: { order_number: @order.order_number, price: @order.price, product_id: @order.product_id }
|
39
|
+
assert_redirected_to order_path(assigns(:order))
|
40
|
+
end
|
41
|
+
|
42
|
+
test "should destroy order" do
|
43
|
+
assert_difference('Order.count', -1) do
|
44
|
+
delete :destroy, id: @order
|
45
|
+
end
|
46
|
+
|
47
|
+
assert_redirected_to orders_path
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ProductsControllerTest < ActionController::TestCase
|
4
|
+
setup do
|
5
|
+
@product = products(:one)
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should get index" do
|
9
|
+
get :index
|
10
|
+
assert_response :success
|
11
|
+
assert_not_nil assigns(:products)
|
12
|
+
end
|
13
|
+
|
14
|
+
test "should get new" do
|
15
|
+
get :new
|
16
|
+
assert_response :success
|
17
|
+
end
|
18
|
+
|
19
|
+
test "should create product" do
|
20
|
+
assert_difference('Product.count') do
|
21
|
+
post :create, product: { name: @product.name, price: @product.price }
|
22
|
+
end
|
23
|
+
|
24
|
+
assert_redirected_to product_path(assigns(:product))
|
25
|
+
end
|
26
|
+
|
27
|
+
test "should show product" do
|
28
|
+
get :show, id: @product
|
29
|
+
assert_response :success
|
30
|
+
end
|
31
|
+
|
32
|
+
test "should get edit" do
|
33
|
+
get :edit, id: @product
|
34
|
+
assert_response :success
|
35
|
+
end
|
36
|
+
|
37
|
+
test "should update product" do
|
38
|
+
put :update, id: @product, product: { name: @product.name, price: @product.price }
|
39
|
+
assert_redirected_to product_path(assigns(:product))
|
40
|
+
end
|
41
|
+
|
42
|
+
test "should destroy product" do
|
43
|
+
assert_difference('Product.count', -1) do
|
44
|
+
delete :destroy, id: @product
|
45
|
+
end
|
46
|
+
|
47
|
+
assert_redirected_to products_path
|
48
|
+
end
|
49
|
+
end
|
File without changes
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rails/performance_test_help'
|
3
|
+
|
4
|
+
class BrowsingTest < ActionDispatch::PerformanceTest
|
5
|
+
# Refer to the documentation for all available options
|
6
|
+
# self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
|
7
|
+
# :output => 'tmp/performance', :formats => [:flat] }
|
8
|
+
|
9
|
+
def test_homepage
|
10
|
+
get '/'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path('../../config/environment', __FILE__)
|
3
|
+
require 'rails/test_help'
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
7
|
+
#
|
8
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
9
|
+
# -- they do not yet inherit this setting
|
10
|
+
fixtures :all
|
11
|
+
|
12
|
+
# Add more helper methods to be used by all tests here...
|
13
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
# Adapted from code by Jon Leighton and adopted from Draper gem
|
5
|
+
# https://github.com/jonleighton/focused_controller/blob/ec7ccf1/test/acceptance/app_test.rb
|
6
|
+
# https://github.com/drapergem/draper
|
7
|
+
|
8
|
+
class DummyApp
|
9
|
+
|
10
|
+
def initialize(environment)
|
11
|
+
raise ArgumentError, "Environment must be development or production" unless ["development", "production"].include?(environment.to_s)
|
12
|
+
@environment = environment
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :environment
|
16
|
+
|
17
|
+
def url
|
18
|
+
"http://#{localhost}:#{port}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(path)
|
22
|
+
Net::HTTP.get(URI(url + path))
|
23
|
+
end
|
24
|
+
|
25
|
+
def within_app(&block)
|
26
|
+
Dir.chdir(root, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def start_server
|
30
|
+
within_app do
|
31
|
+
IO.popen("bundle exec rails s -e #{@environment} -p #{port} 2>&1") do |out|
|
32
|
+
start = Time.now
|
33
|
+
started = false
|
34
|
+
output = ""
|
35
|
+
timeout = 60.0
|
36
|
+
|
37
|
+
while !started && !out.eof? && Time.now - start <= timeout
|
38
|
+
output << read_output(out)
|
39
|
+
sleep 0.1
|
40
|
+
|
41
|
+
begin
|
42
|
+
TCPSocket.new(localhost, port)
|
43
|
+
rescue Errno::ECONNREFUSED
|
44
|
+
else
|
45
|
+
started = true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
raise "Server failed to start:\n#{output}" unless started
|
50
|
+
|
51
|
+
yield
|
52
|
+
|
53
|
+
Process.kill("KILL", out.pid)
|
54
|
+
File.delete("tmp/pids/server.pid")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def root
|
62
|
+
File.expand_path("../../dummy", __FILE__)
|
63
|
+
end
|
64
|
+
|
65
|
+
def localhost
|
66
|
+
"127.0.0.1"
|
67
|
+
end
|
68
|
+
|
69
|
+
def port
|
70
|
+
@port ||= begin
|
71
|
+
server = TCPServer.new(localhost, 0)
|
72
|
+
server.addr[1]
|
73
|
+
ensure
|
74
|
+
server.close if server
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def read_output(stream)
|
79
|
+
read = IO.select([stream], [], [stream], 0.1)
|
80
|
+
output = ""
|
81
|
+
loop { output << stream.read_nonblock(1024) } if read
|
82
|
+
output
|
83
|
+
rescue Errno::EAGAIN, Errno::EWOULDBLOCK, EOFError
|
84
|
+
output
|
85
|
+
end
|
86
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path('../dummy/config/environment', __FILE__)
|
3
|
+
require File.expand_path('../../lib/simple_form_class', __FILE__)
|
4
|
+
|
5
|
+
require "minitest/autorun"
|
6
|
+
require "minitest/unit"
|
7
|
+
require "minitest/rails/shoulda"
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
class MiniTest::Spec
|
12
|
+
|
13
|
+
def assert_difference command, expected_delta, message = 'difference must be equal'
|
14
|
+
rv = eval command
|
15
|
+
yield
|
16
|
+
delta = eval(command) - rv
|
17
|
+
|
18
|
+
assert_equal expected_delta, delta, message
|
19
|
+
end
|
20
|
+
|
21
|
+
# asserts an object does not pass validation, for example:
|
22
|
+
#
|
23
|
+
# test for invalid on one and two attributes with no specific messages:
|
24
|
+
#
|
25
|
+
# assert_invalid @user_card, :masked_pan, 'second user_card'
|
26
|
+
# assert_invalid @user_card, [:masked_pan, :hashed_pan], 'second user_card'
|
27
|
+
#
|
28
|
+
# test for invalid on one and attributes with specific messages - please note
|
29
|
+
# that validation messages are often used to configure display of certain messages
|
30
|
+
# in the view layer, this is why using specific messages may lead to brittle
|
31
|
+
# tests that result in false positive assertions after view layer changes
|
32
|
+
#
|
33
|
+
# assert_invalid @user_card, {:masked_pan => 'has already been taken'}, 'second user_card'
|
34
|
+
# assert_invalid @user_card, {:masked_pan => 'has already been taken', :hashed_pan => 'is not a hash'}, 'second user_card'
|
35
|
+
def assert_invalid object, errors, message = nil
|
36
|
+
refute object.valid?, [message, 'expected to be invalid'].compact.join(': ')
|
37
|
+
|
38
|
+
errors = [errors] unless errors.respond_to? :each
|
39
|
+
|
40
|
+
errors.each do |attribute, error_message|
|
41
|
+
assert object.errors.messages.has_key?(attribute),
|
42
|
+
[message, "expected to have a validation error on #{attribute}, but got #{object.errors.messages}"].compact.join(': ')
|
43
|
+
|
44
|
+
if error_message
|
45
|
+
assert object.errors.messages[attribute].include?(error_message),
|
46
|
+
[message, "expected to have a validation error for '#{error_message}' on #{attribute}, got #{object.errors.messages[attribute]}"].compact.join(': ')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# asserts an object is valid, for example:
|
52
|
+
#
|
53
|
+
# assert_valid user_card, 'first user_card'
|
54
|
+
# c1.save # will always pass
|
55
|
+
def assert_valid object, message = nil
|
56
|
+
# Rails 3.0 have error_messages, Rails > 3.0 have errors.messages
|
57
|
+
error_messages = if ENV['RAILS_VERSION'] == '3.0'
|
58
|
+
object.errors.full_messages
|
59
|
+
else
|
60
|
+
object.errors.messages
|
61
|
+
end
|
62
|
+
|
63
|
+
assert object.valid?, [message, "expected to be valid, got #{error_messages}"].compact.join(': ')
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BaseTest < MiniTest::Spec
|
4
|
+
|
5
|
+
# TODO: make the rake job work, bundle exec ruby -I lib -I test test/unit/*_test.rb
|
6
|
+
|
7
|
+
class TestException < Exception; end
|
8
|
+
|
9
|
+
NON_YIELD_CALLBACKS = [:before_save, :after_save, :before_initialize, :after_initialize,
|
10
|
+
:before_validation, :after_validation
|
11
|
+
]
|
12
|
+
YIELD_CALLBACKS = [:around_save, :around_initialize, :around_validation]
|
13
|
+
CALLBACKS = NON_YIELD_CALLBACKS + YIELD_CALLBACKS
|
14
|
+
|
15
|
+
context :callbacks do
|
16
|
+
|
17
|
+
should "get triggered on class methods" do
|
18
|
+
@class = Class.new(SimpleFormClass::Base) do
|
19
|
+
|
20
|
+
attr_reader :callbacks
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@callbacks = []
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
CALLBACKS.each do |callback|
|
28
|
+
self.send(callback) do
|
29
|
+
yield if block_given?
|
30
|
+
@callbacks << callback
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
@dummy_instance = @class.new # initialize callbacks
|
36
|
+
assert_valid @dummy_instance, "test case setup problem, @dummy_instance is not valid" # also, validation callbacks
|
37
|
+
@dummy_instance.save # save callbacks
|
38
|
+
|
39
|
+
CALLBACKS.each do |callback|
|
40
|
+
assert_includes @dummy_instance.callbacks, callback,
|
41
|
+
"expected #{callback} to leave a trace in callbacks array, that didn't happen"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
should_eventually "get triggered on callback method override" do
|
46
|
+
@class = Class.new(SimpleFormClass::Base) do
|
47
|
+
|
48
|
+
attr_reader :callbacks
|
49
|
+
|
50
|
+
def initialize
|
51
|
+
@callbacks = []
|
52
|
+
super
|
53
|
+
end
|
54
|
+
|
55
|
+
CALLBACKS.each do |callback|
|
56
|
+
class_eval <<-RUBY
|
57
|
+
def #{callback}
|
58
|
+
yield if block_given?
|
59
|
+
@callbacks << callback
|
60
|
+
end
|
61
|
+
RUBY
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
@dummy_instance = @class.new # initialize callbacks
|
66
|
+
assert_valid @dummy_instance, "test case setup problem, @dummy_instance is not valid" # also, validation callbacks
|
67
|
+
@dummy_instance.save # save callbacks
|
68
|
+
|
69
|
+
CALLBACKS.each do |callback|
|
70
|
+
assert_includes @dummy_instance.callbacks, callback,
|
71
|
+
"expected #{callback} to leave a trace in callbacks array, that didn't happen"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
context :owners do
|
78
|
+
|
79
|
+
setup do
|
80
|
+
@class = Class.new(SimpleFormClass::Base) do
|
81
|
+
add_owner :test
|
82
|
+
|
83
|
+
field :foo_test, :owner => :foo
|
84
|
+
field :self_test, :owner => :self
|
85
|
+
end
|
86
|
+
|
87
|
+
@dummy_instance = @class.new do |o|
|
88
|
+
o.foo = Product.new
|
89
|
+
o.test = Order.new
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
should "behave like ActiveModel objects and raise otherwise" do
|
94
|
+
assert_raises SimpleFormClass::InvalidOwner do
|
95
|
+
@class.new do |o|
|
96
|
+
o.test = Object.new
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
should "generate a proper owner hash" do
|
102
|
+
owner_hash = @dummy_instance.send :owner_hash
|
103
|
+
|
104
|
+
assert_kind_of Hash, owner_hash, "owner_hash is of wrong type"
|
105
|
+
assert_equal [:test, :foo, :self], owner_hash.keys, "owner_hash has wrong keys"
|
106
|
+
|
107
|
+
assert_kind_of Product, owner_hash[:foo], 'wrong class for :foo'
|
108
|
+
assert_kind_of Order, owner_hash[:test], 'wrong class for :test'
|
109
|
+
assert_equal @dummy_instance, owner_hash[:self], 'wrong instance for :self'
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
context :field do
|
116
|
+
|
117
|
+
setup do
|
118
|
+
@class = Class.new(SimpleFormClass::Base) do
|
119
|
+
field :self_foo, :owner => :self, :write => true
|
120
|
+
field :price, :owner => :owner, :write => true
|
121
|
+
|
122
|
+
field :self_boo, :owner => :self
|
123
|
+
field :name, :owner => :owner
|
124
|
+
end
|
125
|
+
|
126
|
+
@owner = Product.new
|
127
|
+
|
128
|
+
@form = @class.new do |o|
|
129
|
+
o.owner = @owner
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# NOTE: only mass assignment is squashed, not regular assignment
|
134
|
+
|
135
|
+
should "work as attr_accessor on self regardless of write flag" do
|
136
|
+
@form.self_foo = 10
|
137
|
+
assert_equal 10, @form.self_foo, "expected self_foo to change state after setter"
|
138
|
+
|
139
|
+
@form.self_boo = 11
|
140
|
+
assert_equal 11, @form.self_boo, "expected self_boo to change state after setter"
|
141
|
+
end
|
142
|
+
|
143
|
+
should "work as delegator on owned regardless of write flag" do
|
144
|
+
@form.price = 12
|
145
|
+
assert_equal 12, @form.price, "expected message to change state after setter on @form"
|
146
|
+
assert_equal 12, @form.owner.price, "expected message to change state after setter on @form.owner"
|
147
|
+
assert_equal 12, @owner.price, "expected message to change state after setter on @owner"
|
148
|
+
|
149
|
+
@form.name = 13
|
150
|
+
assert_equal 13, @form.name, "expected params to change state after setter on @form"
|
151
|
+
assert_equal 13, @form.owner.name, "expected params to change state after setter on @form.owner"
|
152
|
+
assert_equal 13, @owner.name, "expected params to change state after setter on @owner"
|
153
|
+
end
|
154
|
+
|
155
|
+
context "mass assignment" do
|
156
|
+
|
157
|
+
should "work on all attributes if not params.is_a? ActionController::Parameters" do
|
158
|
+
params = { self_foo: 20, price: 21, self_boo: 22, name: 23 }
|
159
|
+
assert_kind_of Hash, params, "test case setup problem, params is of wrong class"
|
160
|
+
|
161
|
+
form = @class.new(params) do |o|
|
162
|
+
o.owner = @owner
|
163
|
+
end
|
164
|
+
|
165
|
+
assert_equal 20, form.self_foo, "expected self_foo to get mass assigned"
|
166
|
+
assert_equal 21, form.price, "expected message to get mass assigned"
|
167
|
+
|
168
|
+
assert_equal 22, form.self_boo, "expected self_boo to get mass assigned"
|
169
|
+
assert_equal 23, form.name, "expected params to get mass assigned"
|
170
|
+
end
|
171
|
+
|
172
|
+
should "filter attributes without write: true if params.is_a? ActionController::Parameters" do
|
173
|
+
params = ActionController::Parameters.new(self_foo: 30, price: 31, self_boo: 32, name: 33)
|
174
|
+
assert_kind_of ActionController::Parameters, params, "test case setup problem, params is of wrong class"
|
175
|
+
|
176
|
+
form = @class.new(params) do |o|
|
177
|
+
o.owner = @owner
|
178
|
+
end
|
179
|
+
|
180
|
+
assert_equal 30, form.self_foo, "expected self_foo to get mass assigned"
|
181
|
+
assert_equal 31, form.price, "expected message to get mass assigned"
|
182
|
+
assert_equal nil, form.self_boo, "expected self_boo to get filtered out"
|
183
|
+
assert_equal nil, form.name, "expected params to get filtered out"
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
context :validators do
|
191
|
+
|
192
|
+
# TODO
|
193
|
+
should_eventually :get_tested do; end
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
context :inheritancs do
|
198
|
+
|
199
|
+
# TODO
|
200
|
+
should_eventually :propagate_owners_to_subclass do; end
|
201
|
+
should_eventually :propagate_fields_to_subclass do; end
|
202
|
+
|
203
|
+
# TODO
|
204
|
+
should_eventually :not_cumulatively_add_owners do; end # see #831
|
205
|
+
should_eventually :not_cumulatively_add_fields do; end # see #831
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
|
210
|
+
end
|