Sha256: e54d9d108641b7c61c3c1914aa8b3593752ddfd7fba4166f6488e65e46f58c63

Contents?: true

Size: 1.25 KB

Versions: 9

Compression:

Stored size: 1.25 KB

Contents

require 'spec_helper' 

module ActiveAdmin
  class Resource
    describe BelongsTo do

      let(:application){ ActiveAdmin::Application.new }
      let(:namespace){ Namespace.new(application, :admin) }
      let(:post){ namespace.register(Post) }
      let(:belongs_to){ 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
            lambda {
              belongs_to.target
            }.should raise_error(ActiveAdmin::Resource::BelongsTo::TargetNotFound)
          end
        end
      end

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

Version data entries

9 entries across 9 versions & 4 rubygems

Version Path
andrewroth_activeadmin-0.3.4 spec/unit/belongs_to_spec.rb
activeadmin-0.3.4 spec/unit/belongs_to_spec.rb
activeadmin-0.3.3 spec/unit/belongs_to_spec.rb
activeadmin-0.3.2 spec/unit/belongs_to_spec.rb
activeadmin-0.3.1 spec/unit/belongs_to_spec.rb
activeadmin-0.3.0 spec/unit/belongs_to_spec.rb
nsm-activeadmin-0.2.2 spec/unit/belongs_to_spec.rb
saulolso-activeadmin-0.2.2.1 spec/unit/belongs_to_spec.rb
saulolso-activeadmin-0.2.2 spec/unit/belongs_to_spec.rb