Last active
August 29, 2015 13:59
-
-
Save christopherstyles/10921856 to your computer and use it in GitHub Desktop.
Move Clubs application invitation responsibilities to a controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/controllers/admin/clubs/applications/invitations_controller.rb | |
| module Admin | |
| module Clubs | |
| module Applications | |
| # InvitationsController allows an application invitation to be sent, and | |
| # to trigger subsequent actions, such as setting state on the application | |
| # or sending an invitation email. | |
| class InvitationsController < Admin::ApplicationController | |
| respond_to :js | |
| before_filter :set_application | |
| def create | |
| @invitation = @application.invitations.create! | |
| @application.invite | |
| @application.schedulable | |
| ClubsMailer.next_steps_application( | |
| @application.applicant.user.id | |
| ).deliver | |
| end | |
| private | |
| def set_application | |
| @application = ::Clubs::Application.find(params[:application_id]) | |
| end | |
| end | |
| end | |
| end | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # spec/controllers/admin/clubs/applications/invitations_controller_spec.rb | |
| require 'spec_helper' | |
| describe Admin::Clubs::Applications::InvitationsController do | |
| let(:admin_user) { create(:user, :admin) } | |
| let(:application) { create(:clubs_application) } | |
| context 'when signed in' do | |
| before { sign_in(admin_user) } | |
| # POST :create | |
| describe 'POST #create' do | |
| it 'assigns the given application to @application' do | |
| post :create, application_id: application.id | |
| expect(assigns(:application)).to eq(application) | |
| end | |
| it 'creates an invitation notification' do | |
| expect { | |
| post :create, application_id: application.id | |
| }.to change(Clubs::Notification::Invitation, :count).by(1) | |
| end | |
| it 'sets the application state to schedulable' do | |
| post :create, application_id: application.id | |
| application.reload | |
| expect(application.schedulable?).to eq(true) | |
| end | |
| it 'sets the invited_at timestamp' do | |
| Timecop.freeze do | |
| post :create, application_id: application.id | |
| application.reload | |
| expect(application.invited_at.to_i).to eq(Time.now.to_i) | |
| end | |
| end | |
| it 'renders the invite template' do | |
| post :create, application_id: application.id | |
| expect(response).to render_template(:create) | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # config/routes.rb | |
| namespace :clubs do | |
| resources :applications do | |
| scope module: 'applications' do | |
| resource :invitation, only: [:create] | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment