Sha256: 919eba4dd959f5a450bcb09e3e8e97329bf8b6863859ad9532ee5fa19a9c68f5

Contents?: true

Size: 1.8 KB

Versions: 21

Compression:

Stored size: 1.8 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
      expect_any_instance_of(User).to receive(:save)
      User.create(proto)
    end

    it "accepts a hash" do
      expect_any_instance_of(User).to receive(:save)
      User.create(user_attributes)
    end
  end

  describe ".create!" do
    it "accepts a protobuf message" do
      expect_any_instance_of(User).to receive(:save!)
      User.create!(proto)
    end

    it "accepts a hash" do
      expect_any_instance_of(User).to 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)
      expect(user.changed?).to be true
    end

    it "accepts a hash" do
      user.assign_attributes(user_attributes)
      expect(user.changed?).to be true
    end
  end

  describe "#update_attributes" do
    it "accepts a protobuf message" do
      expect_any_instance_of(User).to receive(:save)
      user.update_attributes(proto)
    end

    it "accepts a hash" do
      expect_any_instance_of(User).to receive(:save)
      user.update_attributes(user_attributes)
    end
  end

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

    it "accepts a hash" do
      expect_any_instance_of(User).to receive(:save!)
      user.update_attributes!(user_attributes)
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
protobuf-activerecord-3.6.0 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.5.1 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.5.0 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.4.4 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.4.4.pre spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.4.3 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.4.2 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.4.1 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.4.0 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.3.8 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.3.7 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.3.6 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.3.5 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.3.4 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.3.3 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.3.2 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.3.1 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.3.0 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.2.2 spec/protobuf/active_record/persistence_spec.rb
protobuf-activerecord-3.2.1 spec/protobuf/active_record/persistence_spec.rb