Sha256: b2cd889cb0efd89f8ec51222efe1b310d427d4e6281cb277a8abf2e45ff353e8

Contents?: true

Size: 1.74 KB

Versions: 12

Compression:

Stored size: 1.74 KB

Contents

require 'spec_helper'

describe Protobuf::ActiveRecord::Persistence do
  let(:user) { User.new(user_attributes) }
  let(:user_attributes) { { :first_name => 'foo', :last_name => 'bar', :email => 'foo@test.co' } }
  let(:proto_hash) { { :name => 'foo bar', :email => 'foo@test.co' } }
  let(:proto) { UserMessage.new(proto_hash) }

  describe ".create" do
    it "accepts a protobuf message" do
      User.any_instance.should_receive(:save)
      User.create(proto)
    end

    it "accepts a hash" do
      User.any_instance.should_receive(:save)
      User.create(user_attributes)
    end
  end

  describe ".create!" do
    it "accepts a protobuf message" do
      User.any_instance.should_receive(:save!)
      User.create!(proto)
    end

    it "accepts a hash" do
      User.any_instance.should_receive(:save!)
      User.create!(user_attributes)
    end
  end

  describe "#assign_attributes" do
    let(:user) { ::User.new }

    it "accepts a protobuf message" do
      user.assign_attributes(proto)
      user.changed?.should be_true
    end

    it "accepts a hash" do
      user.assign_attributes(user_attributes)
      user.changed?.should be_true
    end
  end

  describe "#update_attributes" do
    it "accepts a protobuf message" do
      User.any_instance.should_receive(:save)
      user.update_attributes(proto)
    end

    it "accepts a hash" do
      User.any_instance.should_receive(:save)
      user.update_attributes(user_attributes)
    end
  end

  describe "#update_attributes!" do
    it "accepts a protobuf message" do
      User.any_instance.should_receive(:save!)
      user.update_attributes!(proto)
    end

    it "accepts a hash" do
      User.any_instance.should_receive(:save!)
      user.update_attributes!(user_attributes)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
protobuf-activerecord-3.1.1 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.1.0 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.1.0.rc1 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.1.0.alpha2 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.1.0.alpha spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.0.2 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.0.1 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.0.0 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.0.0.rc4 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.0.0.rc3 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.0.0.rc2 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.0.0.pre spec/protobuf/active_record/persistence_spec.rb