Skip to content
This repository was archived by the owner on Mar 10, 2021. It is now read-only.

Commit

Permalink
Accounts user specs
Browse files Browse the repository at this point in the history
  • Loading branch information
archonic committed Apr 5, 2018
1 parent 23bb9be commit d3b6bff
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The gemset has been chosen to be modern, performant, and take care of a number o
* Persistent banner with link to billing page for accounts that are past due.
* Opinionated search integration using Elasticsearch via Searchkick. Gem is in place but integration is up to you.
* Feature control using the flipper gem. Demonstrated with public_registration.
* 82% RSpec test coverage.
* 87% RSpec test coverage.

## Roadmap
* In-browser image cropping using jcrop or the likes.
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/accounts_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class AccountsUsersController < ApplicationController
def destroy
authorize @accounts_user
@accounts_user.discard
SubscriptionsController.new(@accounts_user.account).update_subscription
SubscriptionService.new(@accounts_user.account).update_subscription
flash[:success] = "The user #{@accounts_user.full_name} <#{@accounts_user.email}> has been removed from your account."
redirect_to account_show_path
end
Expand Down
62 changes: 62 additions & 0 deletions spec/requests/accounts_users_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require 'rails_helper'
require 'stripe_mock'

RSpec.describe AccountsController, type: :request do
let(:stripe_helper) { StripeMock.create_test_helper }
before do
StripeMock.start
stripe_helper.create_plan(id: 'example-plan-id', name: 'Pro', amount: 1500, currency: 'usd', trial_period_days: $trial_period_days)
# Allow public registration before testing it
$flipper.enable :public_registration
end

let(:au) { create(:accounts_user, :subscribed) }
let(:account) { au.account }
let(:user) { au.user }

let(:admin_au) { create(:accounts_user, account: account) }
let(:admin) { admin_au.user }

let(:delete_au) { create(:accounts_user, account: account) }

before do
Apartment::Tenant.switch('public') do
admin_au.add_role :admin
end
host! "#{account.subdomain}.lvh.me:3000"
end

describe '#destroy' do
subject do
delete accounts_user_destroy_path(delete_au.id)
response
end

context 'as an admin' do
before { sign_in admin }

it 'deletes the user' do
allow(AccountsUser).to receive(:find).with(
delete_au.id.to_s
).and_return delete_au
expect(delete_au).to receive(:discard).with(no_args).once
subscription_service_dbl = double(SubscriptionService)
expect(SubscriptionService).to receive(:new).with(
account
).and_return subscription_service_dbl
expect(subscription_service_dbl).to receive(:update_subscription).once
expect(subject).to redirect_to(account_show_path)
expect(flash[:success]).to match /has been removed from your account/
end
end

context 'as not an admin' do
before { sign_in user }

it 'raises Pundit::NotAuthorizedError' do
expect(subject).to redirect_to(dashboard_path)
expect(flash[:alert]).to match /Access denied/
end
end
end
end

0 comments on commit d3b6bff

Please sign in to comment.