Sha256: 221375bafbfa32140964fcfe4386c42fb5d48823f9d24e7e5220adf65cfb63dc

Contents?: true

Size: 1.13 KB

Versions: 40

Compression:

Stored size: 1.13 KB

Contents

# encoding: utf-8
require File.join(File.dirname(__FILE__), "../spec_helper.rb")

describe "Her::Model and ActiveModel::Validations" do
  context "validating attributes" do
    before do
      spawn_model "Foo::User" do
        attributes :fullname, :email
        validates_presence_of :fullname
        validates_presence_of :email
      end
    end

    it "validates attributes when calling #valid?" do
      user = Foo::User.new
      user.should_not be_valid
      user.errors.full_messages.should include("Fullname can't be blank")
      user.errors.full_messages.should include("Email can't be blank")
      user.fullname = "Tobias Fünke"
      user.email = "tobias@bluthcompany.com"
      user.should be_valid
    end
  end

  context "handling server errors" do
    before do
      spawn_model("Foo::Model") do
        def errors
          @response_errors
        end
      end

      class User < Foo::Model; end
      @spawned_models << :User
    end

    it "validates attributes when calling #valid?" do
      user = User.new(:_errors => ["Email cannot be blank"])
      user.errors.should include("Email cannot be blank")
    end
  end
end

Version data entries

40 entries across 40 versions & 4 rubygems

Version Path
her5-0.8.1 spec/model/validations_spec.rb
her-0.8.1 spec/model/validations_spec.rb
her-0.7.6 spec/model/validations_spec.rb
her-0.7.5 spec/model/validations_spec.rb
her-0.7.4 spec/model/validations_spec.rb
herr-0.7.3 spec/model/validations_spec.rb
her-0.7.3 spec/model/validations_spec.rb
her-0.7.2 spec/model/validations_spec.rb
her-0.7.1 spec/model/validations_spec.rb
her-0.7 spec/model/validations_spec.rb
her-0.6.8 spec/model/validations_spec.rb
her-0.6.7 spec/model/validations_spec.rb
her-0.6.6 spec/model/validations_spec.rb
her-0.6.5 spec/model/validations_spec.rb
her-0.6.4 spec/model/validations_spec.rb
her-0.6.3 spec/model/validations_spec.rb
her-0.6.2 spec/model/validations_spec.rb
her-0.6.1 spec/model/validations_spec.rb
her-0.6 spec/model/validations_spec.rb
her-0.5.5 spec/model/validations_spec.rb