Sha256: dea731b36c5317fe3f1d07b694513b99d6908634286a251ad8ccf228f59c224f

Contents?: true

Size: 1.59 KB

Versions: 14

Compression:

Stored size: 1.59 KB

Contents

require 'rails_helper'

describe ActiveAdmin::Resource::BelongsTo do

  let(:user_config){ ActiveAdmin.register User }
  let(:post_config){ ActiveAdmin.register Post do belongs_to :user end }
  let(:belongs_to){ post_config.belongs_to_config }

  it "should have an owner" do
    expect(belongs_to.owner).to eq post_config
  end

  describe "finding the target" do
    context "when the resource has been registered" do
      it "should return the target resource" do
        expect(belongs_to.target).to eq user_config
      end
    end

    context "when the resource has not been registered" do
      let(:belongs_to){ ActiveAdmin::Resource::BelongsTo.new post_config, :missing }

      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_config, :user, optional: true
    expect(belongs_to).to be_optional
  end

  describe "controller" do
    let(:controller) { post_config.controller.new }
    before do
      user = User.create!
      request = double 'Request', format: 'application/json'
      allow(controller).to receive(:params) { {user_id: user.id} }
      allow(controller).to receive(:request){ request }
    end
    it 'should be able to access the collection' do
      expect(controller.send :collection).to be_a ActiveRecord::Relation
    end
    it 'should be able to build a new resource' do
      expect(controller.send :build_resource).to be_a Post
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
yousty-activeadmin-1.0.17.pre spec/unit/belongs_to_spec.rb
yousty-activeadmin-1.0.16.pre spec/unit/belongs_to_spec.rb
yousty-activeadmin-1.0.15.pre spec/unit/belongs_to_spec.rb
yousty-activeadmin-1.0.14.pre spec/unit/belongs_to_spec.rb
yousty-activeadmin-1.0.13.pre spec/unit/belongs_to_spec.rb
yousty-activeadmin-1.0.12.pre spec/unit/belongs_to_spec.rb
yousty-activeadmin-1.0.11.pre spec/unit/belongs_to_spec.rb
yousty-activeadmin-1.0.10.pre spec/unit/belongs_to_spec.rb
yousty-activeadmin-1.0.9.pre spec/unit/belongs_to_spec.rb
yousty-activeadmin-1.0.8.pre spec/unit/belongs_to_spec.rb
activeadmin-1.0.0.pre1 spec/unit/belongs_to_spec.rb
yousty-activeadmin-1.0.7.pre spec/unit/belongs_to_spec.rb
yousty-activeadmin-1.0.6.pre spec/unit/belongs_to_spec.rb
yousty-activeadmin-1.0.5.pre spec/unit/belongs_to_spec.rb