Sha256: fcf57dd043b82db1191d4b33b3bf5abfcd4e1011fe7a3bc414d46fc77a666dd6

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

require 'rails_helper'

RSpec.describe Sample, :type => :model do
  it 'check factory' do
    expect(create(:valid_sample)).to be_a(Sample)
    expect{create(:sample)}.to raise_exception
  end

  context 'presence' do
    [:text, :password, :textarea, :select, :radio, :checkbox].each do |attribute_name|
      it "blank #{attribute_name} get invalid" do
        model = build(:valid_sample)
        model[attribute_name] = nil
        expect(model.has_error_on(attribute_name, :presence)).to be_truthy
      end

      it "input #{attribute_name} get valid" do
        model = build(:valid_sample)
        expect(model.has_error_on(attribute_name, :presence)).to be_falsey
      end
    end
  end

  context 'inclusion' do
    [:select, :radio].each do |attribute_name|
      it "out of selector #{attribute_name} get invalid" do
        model = build(:valid_sample)
        model[attribute_name] = :a
        expect(model.has_error_on(attribute_name, :inclusion)).to be_truthy
      end

      it "in selector #{attribute_name} get valid" do
        model = build(:valid_sample)
        expect(model.has_error_on(attribute_name, :inclusion)).to be_falsey
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yorisoi-0.0.3 spec/models/samples_spec.rb
yorisoi-0.0.2 spec/models/samples_spec.rb
yorisoi-0.0.1 spec/models/samples_spec.rb