Sha256: 34633f0ed17bbd2515ef8fe014c851246f6c243bce830e43ab05c244d843d8b2

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 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
    expect(belongs_to.owner).to eq post
  end

  it "should have a namespace" do
    expect(belongs_to.namespace).to eq 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
        expect(belongs_to.target).to eq 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
    expect(belongs_to).to be_optional
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
active_administration-0.0.3 spec/unit/belongs_to_spec.rb
activeadministration-0.0.2 spec/unit/belongs_to_spec.rb
active_administration-0.0.2 spec/unit/belongs_to_spec.rb
activeadministration-0.0.1 spec/unit/belongs_to_spec.rb
active_administration-0.0.1 spec/unit/belongs_to_spec.rb