Sha256: fa1a1020e0e674b6c825e28c8a787c6a92dd117420197791c1a7488e01d6db9f

Contents?: true

Size: 1.17 KB

Versions: 7

Compression:

Stored size: 1.17 KB

Contents

require 'spec_helper'

describe "display_name" do

  include ActiveAdmin::ViewHelpers

  [:display_name, :full_name, :name, :username, :login, :title, :email, :to_s].each do |m|
    it "should return #{m} when defined" do
      r = Class.new do
        define_method m do
          m.to_s
        end
      end.new
      display_name(r).should == m.to_s
    end
  end

  it "should memeoize the result for the class" do
    subject { Class.new.new }
    subject.should_receive(:name).twice.and_return "My Name"
    display_name(subject).should == "My Name"
    ActiveAdmin.application.should_not_receive(:display_name_methods)
    display_name(subject).should == "My Name"
  end

  it "should not call a method if it's an association" do
    subject { Class.new.new }
    subject.stub_chain(:class, :reflect_on_all_associations).and_return [ mock(:name => :login) ]
    subject.stub :login
    subject.should_not_receive :login
    subject.stub(:email).and_return 'foo@bar.baz'
    display_name(subject).should == 'foo@bar.baz'
  end

  [nil, false].each do |type|
    it "should return nil when the passed object is #{type.inspect}" do
      display_name(type).should eq nil
    end
  end

end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
activeadmin-0.6.6 spec/unit/view_helpers/display_name_spec.rb
activeadmin-0.6.5 spec/unit/view_helpers/display_name_spec.rb
activeadmin-0.6.4 spec/unit/view_helpers/display_name_spec.rb
activeadmin-0.6.3 spec/unit/view_helpers/display_name_spec.rb
activeadmin-0.6.2 spec/unit/view_helpers/display_name_spec.rb
activeadmin-0.6.1 spec/unit/view_helpers/display_name_spec.rb
aa-rails4-0.6.0 spec/unit/view_helpers/display_name_spec.rb