Sha256: 7979280cb88198cfc0f672d0f65081b64a5f4e9603e830049f3132cc2bd03177

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'

describe CurationConcern::LinkedResourcesController do
  let(:user) { FactoryGirl.create(:user) }
  let(:another_user) { FactoryGirl.create(:user) }
  let(:visibility) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE }
  let(:parent) {
    FactoryGirl.create_curation_concern(:generic_work, user, {visibility: visibility})
  }
  let(:you_tube_link) { 'http://www.youtube.com/watch?v=oHg5SJYRHA0' }

  describe '#new' do
    it 'renders a form if you can edit the parent' do
      sign_in(user)
      parent
      get :new, parent_id: parent.to_param
      expect(response).to render_template(:new)
      response.should be_successful
    end

    it 'redirects if you cannot edit the parent' do
      sign_in(another_user)
      parent
      expect {
        get :new, parent_id: parent.to_param
      }.to raise_rescue_response_type(:unauthorized)
    end
  end

  describe '#create' do
    let(:actor) { double('actor') }
    let(:actors_action) { :create }
    let(:success) { true }
    let(:failure) { false }

    it 'redirects to the parent work' do
      sign_in(user)
      parent
      actor.should_receive(actors_action).and_return(success)
      controller.actor = actor

      post(:create, parent_id: parent.to_param,
           linked_resource: { url: you_tube_link }
      )

      expect(response).to(
        redirect_to(controller.polymorphic_path([:curation_concern, parent]))
      )
    end

    describe 'failure' do
      it 'renders the form' do
        sign_in(user)
        parent
        actor.should_receive(actors_action).and_return(failure)
        controller.actor = actor

        post(:create, parent_id: parent.to_param,
             linked_resource: { url: you_tube_link }
        )
        expect(response).to render_template('new')
        response.status.should == 422
      end
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
curate-0.5.1 spec/controllers/curation_concern/linked_resources_controller_spec.rb
curate-0.5.0 spec/controllers/curation_concern/linked_resources_controller_spec.rb
curate-0.4.2 spec/controllers/curation_concern/linked_resources_controller_spec.rb