Sha256: b51d264b22b644dbfc33daa43d321599eab088e038b218e9e7ca953f427de63d

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

require "spec_helper"

describe ::ActiveRemote::QueryAttributes do
  subject { ::Author.new }

  describe "#query_attribute" do
    it "raises when getting an undefined attribute" do
      expect { subject.query_attribute(:foobar) }.to raise_error(::ActiveRemote::UnknownAttributeError)
    end

    it "is false when the attribute is false" do
      subject.name = false
      expect(subject.name?).to eq false
    end

    it "is true when the attribute is true" do
      subject.name = true
      expect(subject.name?).to eq true
    end

    it "is false when the attribute is nil" do
      subject.name = nil
      expect(subject.name?).to eq false
    end

    it "is true when the attribute is an Object" do
      subject.name = Object.new
      expect(subject.name?).to eq true
    end

    it "is false when the attribute is an empty string" do
      subject.name = ""
      expect(subject.name?).to eq false
    end

    it "is true when the attribute is a non-empty string" do
      subject.name = "Chris"
      expect(subject.name?).to eq true
    end

    # This behavior varies from ActiveRecord, so we test it explicitly
    it "is true when the attribute is 0" do
      subject.name = 0
      expect(subject.name?).to eq true
    end

    it "is true when the attribute is 1" do
      subject.name = 1
      expect(subject.name?).to eq true
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
active_remote-5.0.1 spec/lib/active_remote/query_attribute_spec.rb
active_remote-5.1.1 spec/lib/active_remote/query_attribute_spec.rb
active_remote-5.1.0 spec/lib/active_remote/query_attribute_spec.rb
active_remote-5.0.0 spec/lib/active_remote/query_attribute_spec.rb
active_remote-5.1.0.rc1 spec/lib/active_remote/query_attribute_spec.rb
active_remote-5.0.0.rc1 spec/lib/active_remote/query_attribute_spec.rb