Last active
February 12, 2018 23:21
-
-
Save jackiig/b469ec53f658070636d888d8fce78c56 to your computer and use it in GitHub Desktop.
Trying to use virtual collections inside of a virtual collection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Required for anonymous struct of cross_sell products. | |
require 'disposable/twin/struct' # Disposible version 0.4.3. | |
# Contract for validating input for sending an auto email. | |
class Email::ThankYou::Auto::Contract < Reform::Form # Reform version: 2.2.4 | |
# Included for cross_sell to construct itself. | |
include Disposable::Twin::Property::Struct | |
property :username, virtual: true | |
validates :username, presence: true | |
property :password, virtual: true | |
validates :password, presence: true | |
# Tried replacing "Struct" with "OpenStruct", "Array", "Hash", etc. | |
collection :cross_sell, virtual: true, field: :hash, populate_if_empty: Struct do | |
property :product, virtual: true | |
property :enabled, virtual: true | |
property :url, virtual: true | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class EmailContractThankYouAutoTest < MiniTest::Spec | |
describe 'Fields' do | |
let (:fields) { | |
{ | |
username: 'customer123', | |
password: 'SecurePassword', | |
cross_sell: [ | |
{ | |
product: 'Product 1', | |
enabled: true, | |
url: 'https://example.com/prod1/' | |
}, | |
{ | |
product: 'Product 2', | |
enabled: false, | |
url: 'https://example.com/prod2/' | |
} | |
] | |
} | |
} | |
it 'requires all of the fields' do | |
result = Email::ThankYou::Auto::Contract.new({}).call(fields) | |
# Error: | |
# Fields#test_0001_requires all of the fields: | |
# NoMethodError: undefined method `original' for nil:NilClass | |
result.valid?.must_equal true | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment