# Generated via
#  `rails generate hyrax:work <%= class_name %>`
require 'rails_helper'
include Warden::Test::Helpers

# NOTE: If you generated more than one work, you have to set "js: true"
RSpec.feature 'Create a <%= class_name %>', js: false do
  context 'a logged in user' do
    let(:user_attributes) do
      { <%= Hydra.config.user_key_field %>: 'test@example.com' }
    end
    let(:user) do
      User.new(user_attributes) { |u| u.save(validate: false) }
    end

    before do
      AdminSet.find_or_create_default_admin_set_id
      login_as user
    end

    scenario do
      visit '/dashboard'
      click_link "Works"
      click_link "Add new work"

      # If you generate more than one work uncomment these lines
      # choose "payload_concern", option: "<%= class_name %>"
      # click_button "Create work"

      expect(page).to have_content "Add New <%= human_name %>"
    end
  end
end

# Generated via
#  `rails generate hyrax:work <%= class_name %>`
require 'rails_helper'
include Warden::Test::Helpers

# NOTE: If you generated more than one work, you have to set "js: true"
RSpec.feature 'Create a <%= class_name %>', js: false do
  context 'a logged in user' do
    let(:user_attributes) do
      { <%= Hydra.config.user_key_field %>: 'test@example.com' }
    end
    let(:user) do
      User.new(user_attributes) { |u| u.save(validate: false) }
    end
    let(:admin_set_id) { AdminSet.find_or_create_default_admin_set_id }
    let(:permission_template) { Hyrax::PermissionTemplate.find_or_create_by!(admin_set_id: admin_set_id) }

    before do
      # Grant the user access to deposit into the admin set.
      Hyrax::PermissionTemplateAccess.create!(
        permission_template_id: permission_template.id,
        agent_type: 'user',
        agent_id: user.user_key,
        access: 'deposit'
      )
      login_as user
    end

    scenario do
      visit '/dashboard'
      click_link "Works"
      click_link "Add new work"

      # If you generate more than one work uncomment these lines
      # choose "payload_concern", option: "<%= class_name %>"
      # click_button "Create work"

      expect(page).to have_content "Add New <%= human_name %>"
    end
  end
end

Create PermissionTemplateAccess in the generated feature spec
Create PermissionTemplateAccess in the generated feature spec

Previously this generated test would fail, because the user didn't have
access to deposit into the admin set that was created.
