Sha256: 1995073c48a24f4943f8ca991f63436493761f71e76960cbc534e12ea5a1dc2f

Contents?: true

Size: 1.99 KB

Versions: 1

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'
require 'redlock'

feature 'Creating a new child Work', :workflow do
  let(:user) { FactoryGirl.create(:user) }

  let(:redlock_client_stub) { # stub out redis connection
    client = double('redlock client')
    allow(client).to receive(:lock).and_yield(true)
    allow(Redlock::Client).to receive(:new).and_return(client)
    client
  }
  let(:parent) { FactoryGirl.create(:generic_work, user: user, title: ["Parent First"]) }

  before do
    sign_in user

    # stub out characterization. Travis doesn't have fits installed, and it's not relevant to the test.
    allow(CharacterizeJob).to receive(:perform_later)
    redlock_client_stub
    parent
  end

  it 'creates the child work' do
    visit "/concern/parent/#{parent.id}/generic_works/new"
    work_title = 'My Test Work'
    within('form.new_generic_work') do
      fill_in('Title', with: work_title)
      click_on('Create Generic work')
    end
    expect(page).to have_content parent.title.first
    visit "/concern/generic_works/#{parent.id}"
    expect(page).to have_content work_title
  end

  context "when it's being updated" do
    let(:curation_concern) { FactoryGirl.create(:generic_work, user: user) }
    before do
      parent.ordered_members << curation_concern
      parent.save!
    end
    it 'can be updated' do
      visit "/concern/parent/#{parent.id}/generic_works/#{curation_concern.id}/edit"
      click_on "Update Generic work"

      expect(parent.reload.ordered_members.to_a.length).to eq 1
    end
    it "doesn't lose other memberships" do
      new_parent = FactoryGirl.create(:generic_work, user: user)
      new_parent.ordered_members << curation_concern
      new_parent.save!

      visit "/concern/parent/#{parent.id}/generic_works/#{curation_concern.id}/edit"
      click_on "Update Generic work"

      expect(parent.reload.ordered_members.to_a.length).to eq 1
      expect(new_parent.reload.ordered_members.to_a.length).to eq 1

      expect(curation_concern.reload.in_works_ids.length).to eq 2
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
curation_concerns-1.7.0.beta1 spec/features/create_child_work_spec.rb