Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up AuthenticationWorkflow spec helper #5828

Merged
merged 21 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
16b9c8c
Replace usage of create_enterprise_user with :user factory
luisramos0 Jul 27, 2020
3217b3b
Delete dead commented code
luisramos0 Jul 27, 2020
1af4bf6
Replace usage of create_enterprise_user with :user factory
luisramos0 Jul 27, 2020
81710a2
Remove now dead create_enterprise_user, the user factory should be us…
luisramos0 Jul 27, 2020
8e84754
Rename login_as_admin to a more specific name controller_login_as_admin
luisramos0 Jul 27, 2020
f1a3814
Rename login_as_enterprise_user to a more specific name controller_lo…
luisramos0 Jul 27, 2020
8b04e45
Create login_to_admin_and_visit to avoid loading the admin dashboard …
luisramos0 Jul 27, 2020
c6bb756
Rename quick_login_as_admin to login_as_admin and also re-use login_t…
luisramos0 Jul 27, 2020
5738ec0
Rename login_to_admin_and_visit to login_as_admin_and_visit
luisramos0 Jul 27, 2020
10b07aa
Rename quick_login_as to login_as
luisramos0 Jul 27, 2020
a2ebc61
Rename AuthenticationWorkflow to AuthenticationHelper
luisramos0 Jul 27, 2020
d6a5ad7
Adapt specs in order mgmt engine to new authentication helper
luisramos0 Jul 27, 2020
95a9ca7
Remove redundant method, login_as is the name of the test helper in w…
luisramos0 Jul 27, 2020
4df81f0
Remove unnecesasary and now broken require statement from spec and fi…
luisramos0 Jul 27, 2020
27ace50
Fix general settings path in specs
luisramos0 Jul 27, 2020
ecc58ce
Fix navigation problem in spec
luisramos0 Jul 27, 2020
a002ec1
Simplify login_as_admin by using existing factory admin_user
luisramos0 Jul 27, 2020
c923edd
Replace hardcoded URL with path helper
sauloperez Jul 29, 2020
61c14cb
Remove unneeded RSpec config block
sauloperez Aug 4, 2020
9ef59f4
Remove commented out includes
sauloperez Aug 4, 2020
6e39ab7
Make RSpec infer the file type from its location
sauloperez Aug 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop_manual_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ Metrics/MethodLength:
- spec/features/consumer/shopping/checkout_paypal_spec.rb
- spec/features/consumer/shopping/variant_overrides_spec.rb
- spec/models/product_importer_spec.rb
- spec/support/request/authentication_workflow.rb
- spec/support/request/authentication_helper.rb

Metrics/ClassLength:
Max: 100
Expand Down
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ Style/FrozenStringLiteralComment:
- 'spec/support/performance_helper.rb'
- 'spec/support/products_helper.rb'
- 'spec/support/request/admin_helper.rb'
- 'spec/support/request/authentication_workflow.rb'
- 'spec/support/request/authentication_helper.rb'
- 'spec/support/request/checkout_workflow.rb'
- 'spec/support/request/cookie_helper.rb'
- 'spec/support/request/distribution_helper.rb'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
require "spec_helper"

feature "bulk coop" do
include AuthenticationWorkflow
include AuthenticationHelper
include WebHelper

scenario "bulk co-op report" do
quick_login_as_admin
visit spree.admin_reports_path
login_as_admin_and_visit spree.admin_reports_path
click_link 'Bulk Co-Op'
click_button 'Generate Report'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "spec_helper"

feature "enterprise fee summaries", js: true do
include AuthenticationWorkflow
include AuthenticationHelper
include WebHelper

let!(:distributor) { create(:distributor_enterprise) }
Expand Down
4 changes: 1 addition & 3 deletions spec/controllers/admin/bulk_line_items_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require 'spec_helper'

describe Admin::BulkLineItemsController, type: :controller do
include AuthenticationWorkflow

describe '#index' do
render_views

Expand All @@ -17,7 +15,7 @@
let!(:line_item4) { FactoryBot.create(:line_item_with_shipment, order: order3) }

context "as a normal user" do
before { allow(controller).to receive_messages spree_current_user: create_enterprise_user }
before { allow(controller).to receive_messages spree_current_user: create(:user) }

it "should deny me access to the index action" do
spree_get :index, format: :json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Admin::ColumnPreferencesController, type: :controller do
include AuthenticationWorkflow
include AuthenticationHelper

describe "bulk_update" do
let!(:user1) { create(:user) }
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin/customers_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Admin::CustomersController, type: :controller do
include AuthenticationWorkflow
include AuthenticationHelper

describe "index" do
let(:enterprise) { create(:distributor_enterprise) }
Expand Down
32 changes: 10 additions & 22 deletions spec/controllers/admin/enterprises_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
require 'open_food_network/order_cycle_permissions'

describe Admin::EnterprisesController, type: :controller do
include AuthenticationWorkflow

let(:user) { create(:user) }
let(:admin_user) { create(:admin_user) }
let(:distributor_manager) { create(:user, enterprise_limit: 10, enterprises: [distributor]) }
Expand Down Expand Up @@ -138,7 +136,7 @@
let!(:property) { create(:property, name: "A nice name") }

before do
login_as_enterprise_user [producer]
controller_login_as_enterprise_user [producer]
end

context "when a submitted property does not already exist" do
Expand Down Expand Up @@ -179,7 +177,7 @@
let!(:tag_rule) { create(:tag_rule, enterprise: enterprise) }

before do
login_as_enterprise_user [enterprise]
controller_login_as_enterprise_user [enterprise]
end

context "discount order rules" do
Expand Down Expand Up @@ -366,18 +364,8 @@
end

describe "bulk updating enterprises" do
let!(:original_owner) do
user = create_enterprise_user
user.enterprise_limit = 2
user.save!
user
end
let!(:new_owner) do
user = create_enterprise_user
user.enterprise_limit = 2
user.save!
user
end
let!(:original_owner) { create(:user) }
let!(:new_owner) { create(:user) }
let!(:profile_enterprise1) { create(:enterprise, sells: 'none', owner: original_owner ) }
let!(:profile_enterprise2) { create(:enterprise, sells: 'none', owner: original_owner ) }

Expand Down Expand Up @@ -441,7 +429,7 @@
end

describe "for_order_cycle" do
let!(:user) { create_enterprise_user }
let!(:user) { create(:user) }
let!(:enterprise) { create(:enterprise, sells: 'any', owner: user) }
let(:permission_mock) { double(:permission) }

Expand Down Expand Up @@ -487,7 +475,7 @@
end

describe "visible" do
let!(:user) { create(:user, enterprise_limit: 10) }
let!(:user) { create(:user) }
let!(:visible_enterprise) { create(:enterprise, sells: 'any', owner: user) }
let!(:not_visible_enterprise) { create(:enterprise, sells: 'any') }

Expand All @@ -508,10 +496,10 @@
describe "index" do
context "as super admin" do
let(:super_admin) { create(:admin_user) }
let!(:user) { create_enterprise_user(enterprise_limit: 10) }
let!(:user) { create(:user) }
let!(:enterprise1) { create(:enterprise, sells: 'any', owner: user) }
let!(:enterprise2) { create(:enterprise, sells: 'own', owner: user) }
let!(:enterprise3) { create(:enterprise, sells: 'any', owner: create_enterprise_user ) }
let!(:enterprise3) { create(:enterprise, sells: 'any', owner: create(:user) ) }

before do
allow(controller).to receive_messages spree_current_user: super_admin
Expand All @@ -533,10 +521,10 @@
end

context "as an enterprise user" do
let!(:user) { create_enterprise_user(enterprise_limit: 10) }
let!(:user) { create(:user) }
let!(:enterprise1) { create(:enterprise, sells: 'any', owner: user) }
let!(:enterprise2) { create(:enterprise, sells: 'own', owner: user) }
let!(:enterprise3) { create(:enterprise, sells: 'any', owner: create_enterprise_user ) }
let!(:enterprise3) { create(:enterprise, sells: 'any', owner: create(:user) ) }

before do
allow(controller).to receive_messages spree_current_user: user
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin/inventory_items_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Admin::InventoryItemsController, type: :controller do
# include AuthenticationWorkflow
# include AuthenticationHelper

describe "create" do
context "json" do
Expand Down
10 changes: 4 additions & 6 deletions spec/controllers/admin/order_cycles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

module Admin
describe OrderCyclesController, type: :controller do
include AuthenticationWorkflow

let!(:distributor_owner) { create_enterprise_user enterprise_limit: 2 }
let!(:distributor_owner) { create(:user) }

before do
allow(controller).to receive_messages spree_current_user: distributor_owner
Expand Down Expand Up @@ -104,7 +102,7 @@ module Admin
let(:params) { { format: :json, order_cycle: {} } }

before do
login_as_enterprise_user([shop])
controller_login_as_enterprise_user([shop])
allow(OrderCycleForm).to receive(:new) { form_mock }
end

Expand Down Expand Up @@ -150,7 +148,7 @@ def build_resource
end

context "as a manager of the coordinator" do
before { login_as_enterprise_user([coordinator]) }
before { controller_login_as_enterprise_user([coordinator]) }
let(:params) { { format: :json, id: order_cycle.id, order_cycle: {} } }

context "when updating succeeds" do
Expand Down Expand Up @@ -300,7 +298,7 @@ def build_resource
end

describe "notifying producers" do
let(:user) { create_enterprise_user }
let(:user) { create(:user) }
let(:admin_user) do
user = create(:user)
user.spree_roles << Spree::Role.find_or_create_by!(name: 'admin')
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin/proxy_orders_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Admin::ProxyOrdersController, type: :controller do
include AuthenticationWorkflow
include AuthenticationHelper

describe 'cancel' do
let!(:user) { create(:user, enterprise_limit: 10) }
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin/schedules_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Admin::SchedulesController, type: :controller do
include AuthenticationWorkflow
include AuthenticationHelper

describe "index" do
let!(:coordinated_order_cycle) { create(:simple_order_cycle) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Admin::SubscriptionLineItemsController, type: :controller do
include AuthenticationWorkflow
include AuthenticationHelper

describe "build" do
let(:user) { create(:user) }
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin/subscriptions_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Admin::SubscriptionsController, type: :controller do
include AuthenticationWorkflow
include AuthenticationHelper
include OpenFoodNetwork::EmailHelper

describe 'index' do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Admin::VariantOverridesController, type: :controller do
# include AuthenticationWorkflow
# include AuthenticationHelper

describe "bulk_update" do
context "json" do
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/customers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Api
describe CustomersController, type: :controller do
include AuthenticationWorkflow
include AuthenticationHelper
render_views

let(:user) { create(:user) }
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/enterprise_fees_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Api
describe EnterpriseFeesController, type: :controller do
include AuthenticationWorkflow
include AuthenticationHelper

let!(:unreferenced_fee) { create(:enterprise_fee) }
let!(:referenced_fee) { create(:enterprise_fee) }
Expand Down
7 changes: 3 additions & 4 deletions spec/controllers/api/enterprises_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
require 'spec_helper'

describe Api::EnterprisesController, type: :controller do
include AuthenticationWorkflow
render_views

let(:enterprise) { create(:distributor_enterprise) }

context "as an enterprise owner" do
let(:enterprise_owner) { create_enterprise_user enterprise_limit: 10 }
let(:enterprise_owner) { create(:user) }
let!(:enterprise) { create(:distributor_enterprise, owner: enterprise_owner) }

before do
Expand Down Expand Up @@ -52,7 +51,7 @@
end

context "as an enterprise manager" do
let(:enterprise_manager) { create_enterprise_user }
let(:enterprise_manager) { create(:user) }

before do
enterprise_manager.enterprise_roles.build(enterprise: enterprise).save
Expand All @@ -74,7 +73,7 @@
end

context "as an non-managing user" do
let(:non_managing_user) { create_enterprise_user }
let(:non_managing_user) { create(:user) }

before do
allow(Enterprise)
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/exchange_products_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Api
describe ExchangeProductsController, type: :controller do
include AuthenticationWorkflow
include AuthenticationHelper

let(:order_cycle) { create(:order_cycle) }
let(:exchange) { order_cycle.exchanges.incoming.first }
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/logos_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Api
describe LogosController, type: :controller do
include AuthenticationWorkflow
include AuthenticationHelper

let(:admin_user) { create(:admin_user) }
let(:enterprise_owner) { create(:user) }
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/orders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Api
describe OrdersController, type: :controller do
include AuthenticationWorkflow
include AuthenticationHelper
render_views

let!(:regular_user) { create(:user) }
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/product_images_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Api
describe ProductImagesController, type: :controller do
include AuthenticationWorkflow
include AuthenticationHelper
render_views

describe "uploading an image" do
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/promo_images_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Api
describe PromoImagesController, type: :controller do
include AuthenticationWorkflow
include AuthenticationHelper

let(:admin_user) { create(:admin_user) }
let(:enterprise_owner) { create(:user) }
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/shops_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'spec_helper'

describe Api::ShopsController, type: :controller do
include AuthenticationWorkflow
include AuthenticationHelper
render_views

context "as a non-authenticated user" do
Expand Down
5 changes: 2 additions & 3 deletions spec/controllers/registration_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'spec_helper'

describe RegistrationController, type: :controller do
include AuthenticationWorkflow
describe "redirecting when user not logged in" do
it "index" do
get :index
Expand All @@ -10,7 +9,7 @@
end

describe "redirecting when user has reached enterprise ownership limit" do
let!(:user) { create_enterprise_user( enterprise_limit: 1 ) }
let!(:user) { create(:user, enterprise_limit: 1 ) }
let!(:enterprise) { create(:distributor_enterprise, owner: user) }

before do
Expand All @@ -24,7 +23,7 @@
end

describe "loading data when user is logged in" do
let!(:user) { create_enterprise_user }
let!(:user) { create(:user) }

before do
allow(controller).to receive_messages spree_current_user: user
Expand Down