Sha256: 2aceeff315a6ad1a7e2f0267cb65aaa348ea0a4aaf7b9289648e428b5c06d81d

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

require 'rspec'
require 'faker'
require 'active_model'

require 'philtre/filter.rb'

require_relative '../lib/philtre-rails/philtre_model.rb'

# spec/support/active_model_lint.rb
# adapted from rspec-rails:
# http://github.com/rspec/rspec-rails/blob/master/spec/rspec/rails/mocks/mock_model_spec.rb
shared_examples_for "ActiveModel" do
  require 'minitest'
  require 'active_model/lint'

  # needed by MiniTest::Assertions
  def assertions; @assertions ||= 0 end
  def assertions=( rhs ); @assertions = rhs end

  include MiniTest::Assertions

  include ActiveModel::Lint::Tests

  ActiveModel::Lint::Tests
    .public_instance_methods
    .grep(/^test/)
    .each do |test_method|
      example test_method.to_s.gsub('_',' ') do
        send test_method
      end
    end

  # needed for MiniTest::Assertions
  def model; subject end
end

describe Philtre::Filter do

  describe '#to_model' do
    subject{ Philtre::Filter.new( one: 1, two: 2 ) }

    it 'should raise exception' do
      ->{subject.to_model}.should raise_error(/use for_form/i)
    end
  end

  describe '#for_form' do
    subject{ Philtre::Filter.new( one: 1, two: 2 ).for_form }

    it_should_behave_like("ActiveModel")

    it 'nil for not present' do
      subject.three.should be_nil
    end

    it 'value for present' do
      subject.two.should == 2
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
philtre-rails-0.1.0 spec/philtre_model_spec.rb
philtre-rails-0.0.1 spec/philtre_model_spec.rb