spec/dummy/spec/integration/user_params_spec.rb in rom-rails-0.2.1 vs spec/dummy/spec/integration/user_params_spec.rb in rom-rails-0.3.0.beta1
- old
+ new
@@ -3,31 +3,46 @@
describe ROM::Model::Params do
let(:params) do
Class.new do
include ROM::Model::Params
- param_key :test
attribute :name, String
- validates :name, presence: true
- def self.name
- 'Test'
- end
+ timestamps
end
end
- describe '#valid?' do
- it 'returns true when attributes are valid' do
- user_params = params.new(name: 'Jane')
- expect(user_params).to be_valid
+ describe '.timestamps' do
+ it 'provides a way to specify timestamps with default values' do
+ expect(params.new.created_at).to be_a(DateTime)
+ expect(params.new.updated_at).to be_a(DateTime)
end
- it 'returns false when attributes are not valid' do
- user_params = params.new(name: '')
- expect(user_params).not_to be_valid
- end
+ context 'passing in arbritrary names' do
+ it 'excludes :created_at when passing in :updated_at' do
+ params = Class.new {
+ include ROM::Model::Params
- it 'sets up AM name' do
- expect(params.model_name.param_key).to eql('test')
+ timestamps(:updated_at)
+ }
+
+ model = params.new
+
+ expect(model).not_to respond_to(:created_at)
+ expect(model).to respond_to(:updated_at)
+ end
+
+ it 'accepts multiple timestamp attribute names' do
+ params = Class.new {
+ include ROM::Model::Params
+
+ timestamps(:published_at, :revised_at)
+ }
+
+ model = params.new
+
+ expect(model).to respond_to(:published_at)
+ expect(model).to respond_to(:revised_at)
+ end
end
end
end