Sha256: 9913e461cfaa9f3093070fc0250265d3249f25e39dda61f5db417ed2b5164162

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

require 'spec_helper'

describe ActiveAdmin::Resource::BelongsTo do


  let(:application){ ActiveAdmin::Application.new }
  let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
  let(:post){ namespace.register(Post) }
  let(:belongs_to){ ActiveAdmin::Resource::BelongsTo.new(post, :user) }

  it "should have an owner" do
    belongs_to.owner.should == post
  end

  it "should have a namespace" do
    belongs_to.namespace.should == namespace
  end

  describe "finding the target" do
    context "when the resource has been registered" do
      let(:user){ namespace.register(User) }
      before { user } # Ensure user is registered

      it "should return the target resource" do
        belongs_to.target.should == user
      end
    end

    context "when the resource has not been registered" do
      it "should raise a ActiveAdmin::BelongsTo::TargetNotFound" do
        expect {
          belongs_to.target
        }.to raise_error(ActiveAdmin::Resource::BelongsTo::TargetNotFound)
      end
    end
  end

  it "should be optional" do
    belongs_to = ActiveAdmin::Resource::BelongsTo.new post, :user, :optional => true
    belongs_to.should be_optional
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
yousty-activeadmin-1.0.4.pre spec/unit/belongs_to_spec.rb
yousty-activeadmin-1.0.3.pre spec/unit/belongs_to_spec.rb
yousty-activeadmin-1.0.2.pre spec/unit/belongs_to_spec.rb
yousty-activeadmin-1.0.1.pre spec/unit/belongs_to_spec.rb
yousty-activeadmin-1.0.0.pre spec/unit/belongs_to_spec.rb
aa-rails4-0.6.0 spec/unit/belongs_to_spec.rb