Sha256: ab512af814f87a1bc31796a7beb2d3439c634f8c3a5f5fab9091d27a39d75b9b

Contents?: true

Size: 1.68 KB

Versions: 4

Compression:

Stored size: 1.68 KB

Contents

require 'spec_helper'

describe Zertico::Accessor do
  let(:user) { User.new }
  let(:user_accessor) { UserAccessor.new(user) }

  context 'on a namespaced accessor and interface model' do
    it 'should find the interface model' do
      Person::ProfileAccessor.send(:interface_class).should == Person::Profile
    end

    it 'should return a valid instance variable name' do
      Person::ProfileAccessor.send(:interface_name).should == 'profile'
    end
  end

  context 'on a namespaced accessor and non namespaced interface model' do
    it 'should find the interface model' do
      Admin::UserAccessor.send(:interface_class).should == User
    end

    it 'should return a valid instance variable name' do
      Admin::UserAccessor.send(:interface_name).should == 'user'
    end
  end

  context 'on a non namespaced accessor and non namespaced interface model' do
    it 'should find the interface model' do
      UserAccessor.send(:interface_class).should == User
    end

    it 'should return a valid instance variable name' do
      UserAccessor.send(:interface_name).should == 'user'
    end
  end

  describe '.find' do
    before :each do
      User.stub(:find => user)
      UserAccessor.stub(:new => user_accessor)
    end

    it 'should return an accessor' do
      UserAccessor.find(3).should == user_accessor
    end
  end

  describe '#interface' do
    before :each do
      User.stub(:find => user)
    end

    it 'should return the interface object' do
      UserAccessor.find(3).interface.should == user
    end
  end

  describe '#method_missing' do
    it 'should pass the method to the interface model if it responds to it' do
      user_accessor.should respond_to(:full_name)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zertico-1.2.0 spec/zertico/accessor_spec.rb
zertico-1.1.1 spec/zertico/accessor_spec.rb
zertico-1.1.0 spec/zertico/accessor_spec.rb
zertico-1.0.0 spec/zertico/accessor_spec.rb