Skip to content

Commit

Permalink
rubocop fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nwoodward committed Oct 12, 2018
1 parent aeb9904 commit 1b3c5ed
Show file tree
Hide file tree
Showing 38 changed files with 119 additions and 37 deletions.
6 changes: 6 additions & 0 deletions spec/controllers/account_sign_up_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
before do
allow(Settings.multitenancy).to receive(:admin_only_tenant_creation).and_return(false)
end

describe "GET #new" do
it "assigns a new account as @account" do
get :new
Expand Down Expand Up @@ -68,12 +69,14 @@
before do
allow(Settings.multitenancy).to receive(:admin_only_tenant_creation).and_return(true)
end

describe "GET #new" do
it "redirects to sign in" do
get :new
expect(response).to redirect_to new_user_session_path
end
end

describe "POST #create" do
it "redirects to sign in" do
post :create, params: { account: valid_attributes }
Expand All @@ -88,17 +91,20 @@
before do
allow(Settings.multitenancy).to receive(:admin_only_tenant_creation).and_return(true)
end

describe "GET #new" do
it "assigns a new account as @account" do
get :new
expect(response).to render_template("layouts/proprietor")
expect(assigns(:account)).to be_a_new(Account)
end
end

describe "POST #create" do
before do
allow_any_instance_of(CreateAccount).to receive(:create_external_resources)
end

it "creates a new Account" do
expect do
post :create, params: { account: valid_attributes }
Expand Down
1 change: 1 addition & 0 deletions spec/controllers/admin/groups_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
subject { Hyku::Group.find_by(id: group.id) }

before { delete :destroy, params: { id: group.id } }

it { is_expected.to be_nil }
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/controllers/admin/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
subject { User.find_by(id: user.id) }

before { delete :destroy, params: { id: user.id } }

it "doesn't delete the user and redirects to login" do
expect(subject).not_to be_nil
expect(response).to redirect_to root_path
Expand All @@ -22,6 +23,7 @@
subject { User.find_by(id: user.id) }

before { delete :destroy, params: { id: user.to_param } }

it "deletes the user and displays success message" do
expect(subject).to be_nil
expect(flash[:notice]).to eq "User \"#{user.email}\" has been successfully deleted."
Expand Down
1 change: 1 addition & 0 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
sign_in create(:user)
allow(controller).to receive(:can?).and_return(true)
end

it "is successful" do
get :show, params: { id: file_set }
expect(response).to be_successful
Expand Down
3 changes: 3 additions & 0 deletions spec/controllers/hyku/registrations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
expect(response).to render_template('devise/registrations/new')
end
end

describe '#create' do
it 'processes the form' do
post :create, params: {
Expand All @@ -28,6 +29,7 @@
end
end
end

context 'with account signup disabled' do
let(:account_signup_enabled) { false }

Expand All @@ -38,6 +40,7 @@
expect(flash[:alert]).to eq 'Account registration is disabled'
end
end

describe '#create' do
it 'redirects with a flash message' do
post :create
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
RSpec.describe Hyrax::Admin::AppearancesController, type: :controller, singletenant: true do
before { sign_in user }

routes { Hyrax::Engine.routes }

context 'with an unprivileged user' do
Expand Down
2 changes: 2 additions & 0 deletions spec/controllers/hyrax/generic_works_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
fixture_file('images/world.png'),
:original_file)
end

describe '#manifest' do
let(:manifest_factory) { double(to_h: { test: 'manifest' }) }

Expand All @@ -30,6 +31,7 @@
before do
allow(controller).to receive(:curation_concern_from_search_results).and_return(solr_document)
end

subject { controller.send :presenter }

it "initializes a presenter" do
Expand Down
11 changes: 6 additions & 5 deletions spec/factories/generic_works.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
title { ["Test title"] }

identifier { %w[
ISBN:978-83-7659-303-6 978-3-540-49698-4 9790879392788
doi:10.1038/nphys1170 3-921099-34-X 3-540-49698-x 0-19-852663-6
] }
ISBN:978-83-7659-303-6 978-3-540-49698-4 9790879392788
doi:10.1038/nphys1170 3-921099-34-X 3-540-49698-x 0-19-852663-6
]
}

factory :work_with_one_file do
before(:create) do |work, evaluator|
work.ordered_members << FactoryBot.create(:file_set,
user: evaluator.user,
title: ['A Contained Generic File'])
user: evaluator.user,
title: ['A Contained Generic File'])
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/features/accounts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
let(:user) { FactoryBot.create(:superadmin) }
let(:account) do
FactoryBot.create(:account, solr_endpoint_attributes: { url: 'http://localhost:8080/solr' },
fcrepo_endpoint_attributes: { url: 'http://localhost:8080/fcrepo' })
fcrepo_endpoint_attributes: { url: 'http://localhost:8080/fcrepo' })
end

before do
Expand Down
2 changes: 2 additions & 0 deletions spec/features/labels_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
institution_name_full: 'fullname'
)
end

it 'updates the institution name in the agreement text' do
visit edit_site_labels_path
fill_in 'Institution name', with: 'Custom Inst Name'
Expand All @@ -47,6 +48,7 @@
institution_name: 'name'
)
end

it 'updates the full institution name in the agreement text' do
visit edit_site_labels_path
fill_in 'Full institution name', with: 'Custom Full Inst Name'
Expand Down
4 changes: 2 additions & 2 deletions spec/jobs/cleanup_account_job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
RSpec.describe CleanupAccountJob do
let!(:account) do
FactoryBot.create(:account, solr_endpoint_attributes: { collection: 'x' },
fcrepo_endpoint_attributes: { base_path: '/x' },
redis_endpoint_attributes: { namespace: 'x' })
fcrepo_endpoint_attributes: { base_path: '/x' },
redis_endpoint_attributes: { namespace: 'x' })
end

before do
Expand Down
3 changes: 2 additions & 1 deletion spec/jobs/import_work_from_purl_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# Don't call load_workflows until the PermissionTemplate has been created
Hyrax::Workflow::WorkflowImporter.load_workflows
end

let(:purl_xml) do
<<~EOF
<?xml version="1.0" encoding="UTF-8"?>
Expand Down Expand Up @@ -140,7 +141,7 @@
</releaseData>
<thumb>bc390xk2647/00007845_005.jp2</thumb>
</publicObject>
EOF
EOF
end

it "works" do
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/importer/csv_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
context 'when the model is passed' do
let(:csv_file) { "#{fixture_path}/csv/gse_metadata.csv" }
let(:importer) { described_class.new(csv_file, image_directory, fallback_class) }
let(:fallback_class) { Class.new { def initialize(_x, _y); end } }
let(:fallback_class) { Class.new { def initialize(_argx, _argy); end } }
let(:factory) { double(run: true) }

# note: 2 rows do not specify type, 17 do
it 'creates new works' do
expect(fallback_class).to receive(:new)
.with(any_args).and_return(factory).exactly(2).times
.with(any_args).and_return(factory).twice
expect(Importer::Factory::ETDFactory).to receive(:new)
.with(any_args).and_return(factory).exactly(17).times
importer.import_all
Expand Down
10 changes: 5 additions & 5 deletions spec/lib/importer/factory/string_literal_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
let(:name) { ["Muybridge"] }

it do
is_expected.to eq(title: ["Stanford residences"],
contributor: ['Muybridge'])
expect(subject).to eq(title: ["Stanford residences"],
contributor: ['Muybridge'])
end
end

context "with multiple name parts" do
let(:name) { ["Stanford University", "Archives."] }

it do
is_expected.to eq(title: ["Stanford residences"],
contributor: ['Stanford University — Archives.'])
expect(subject).to eq(title: ["Stanford residences"],
contributor: ['Stanford University — Archives.'])
end
end

Expand All @@ -31,6 +31,6 @@
{ title: ["Stanford residences"] }
end

it { is_expected.to eq(title: ["Stanford residences"]) }
it { expect(subject).to eq(title: ["Stanford residences"]) }
end
end
2 changes: 2 additions & 0 deletions spec/lib/importer/mods_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
end

before { allow(parser).to receive(:mods).and_return(Mods::Record.new.from_str(xml)) }

it 'imports date_copyrighted' do
expect(attributes[:date_copyrighted_attributes]).to eq [
{ start: ['1985-12-01'],
Expand All @@ -186,6 +187,7 @@
end

before { allow(parser).to receive(:mods).and_return(Mods::Record.new.from_str(xml)) }

it 'imports date_valid' do
expect(attributes[:date_valid_attributes]).to eq [
{ start: ['1989-12-01'],
Expand Down
8 changes: 8 additions & 0 deletions spec/models/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
described_class.tenants(nil)
end
end

context 'when tenant_list param is empty' do
it 'calls Account.all' do
expect(Account).to receive(:all)
described_class.tenants([])
end
end

context 'when tenant_list param is a string' do
it 'calls Account.where' do
expect(Account).to receive(:where).with(cname: 'foo bar baz')
Expand Down Expand Up @@ -261,6 +263,7 @@
Site.update(account: account)
Site.instance.admin_emails = ["[email protected]", "[email protected]"]
end

it 'switches to current tenant database and returns Site admin_emails' do
expect(Apartment::Tenant).to receive(:switch).with(account.tenant).and_yield
expect(account.admin_emails).to match_array(["[email protected]", "[email protected]"])
Expand All @@ -274,6 +277,7 @@
Site.update(account: account)
Site.instance.admin_emails = ["[email protected]", "[email protected]"]
end

it 'switches to current tenant database updates Site admin_emails' do
expect(Apartment::Tenant).to receive(:switch).with(account.tenant).exactly(3).times.and_yield
expect(account.admin_emails).to match_array(["[email protected]", "[email protected]"])
Expand All @@ -288,19 +292,23 @@
context 'default setting for test environment' do
it { is_expected.to be false }
end

context 'single tenant in production environment' do
before do
allow(Settings.multitenancy).to receive(:enabled).and_return false
allow(Rails.env).to receive(:test?).and_return false
end

it { is_expected.to be false }
end

context 'default tenant in a multitenant production environment' do
before do
allow(Settings.multitenancy).to receive(:enabled).and_return true
allow(Rails.env).to receive(:test?).and_return false
allow(Apartment::Tenant).to receive(:current_tenant).and_return Apartment::Tenant.default_tenant
end

it { is_expected.to be true }
end
end
Expand Down
4 changes: 3 additions & 1 deletion spec/models/nil_site_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@

it { is_expected.to be_empty }
end

context "set a value" do
before { instance.admin_emails = "[email protected]" }
subject { instance.admin_emails }

before { instance.admin_emails = "[email protected]" }

it { is_expected.to be_empty }
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/models/site_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
before do
allow(Account).to receive(:global_tenant?).and_return true
end

it "is a NilSite" do
expect(described_class.instance).to eq(NilSite.instance)
end
end

context "on a specific tenant" do
it "is a singleton site" do
expect(described_class.instance).to eq(described_class.instance)
Expand All @@ -27,11 +29,13 @@
expect(subject.admin_emails).to eq([])
end
end

context "admins exist" do
before do
admin1.add_role :admin, subject
admin2.add_role :admin, subject
end

it "returns array of emails" do
expect(subject.admin_emails).to match_array([admin1.email, admin2.email])
end
Expand All @@ -46,17 +50,20 @@
admin1.add_role :admin, subject
admin2.add_role :admin, subject
end

it "clears out all admins" do
expect(subject.admin_emails).to match_array([admin1.email, admin2.email])
subject.admin_emails = []
expect(subject.admin_emails).to eq([])
end
end

context "passed a new set of admins" do
before do
admin1.add_role :admin, subject
admin2.add_role :admin, subject
end

it "overwrites existing admins with new set" do
expect(subject.admin_emails).to match_array([admin1.email, admin2.email])
subject.admin_emails = [admin3.email, admin1.email]
Expand Down
1 change: 1 addition & 0 deletions spec/models/solr_endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
# Mocking on the subject, because mocking RSolr.connect causes doubles to leak for some reason
allow(subject).to receive(:connection).and_return(mock_connection)
end

it 'checks if the service is up' do
allow(mock_connection).to receive(:get).with('admin/ping').and_return('status' => 'OK')
expect(subject.ping).to be_truthy
Expand Down
Loading

0 comments on commit 1b3c5ed

Please sign in to comment.