Sha256: 9a3286346bb7ee3bd756d25bafd3a0a6dcdfb1b16518d27997146d0f837aa1a9

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'

describe EntityController, :type => :controller do
  before(:all) do
    @john    = User.create!   :admin => false
    @maria   = User.create!   :admin => false
    @admin   = User.create!   :admin => true
    @private = Entity.create! :name => 'ent1', :public => false
    @public  = Entity.create! :name => 'ent1', :public => true, :owner_id => @john.id
  end

  describe "shows everything to admin" do
    it "showws everything to the admin" do
      User.mock @admin
      get :index

      assigns(:entities).count.should == 2
    end

    it "hides non-public entities" do
      User.mock @john
      get :index

      assigns(:entities).count.should == 1
    end

    it "allows creation for admin" do
      User.mock @admin
      post :create, {}

      assigns(:entity).should be_kind_of Heimdallr::Proxy::Record
    end

    it "disallows creation for non-admin" do
      User.mock @john
      expect { post :create, {} }.should raise_error
    end

    it "allows update for admin" do
      User.mock @admin
      post :update, {:id => 1}

      assigns(:entity).should be_kind_of Heimdallr::Proxy::Record
      assigns(:entity).id.should == 1
    end

    it "disallows update for non-admin" do
      User.mock @john
      expect { post :update, {:id => 2} }.should raise_error
    end

    it "allows destroy for admin" do
      User.mock @admin
      post :destroy, {:id => 1}

      assigns(:entity).should be_kind_of Heimdallr::Proxy::Record
      assigns(:entity).id.should == 1
    end

    it "allows destroy for owner" do
      User.mock @john
      post :destroy, {:id => 2}

      assigns(:entity).should be_kind_of Heimdallr::Proxy::Record
      assigns(:entity).id.should == 2
    end

    it "disallows destroy for nobody" do
      User.mock @maria
      expect { post :destroy, {:id => 2} }.should raise_error
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
heimdallr-resource-1.0.0 spec/resource_spec.rb