Skip to content

Commit

Permalink
Migrate controller test to request/routing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MaicolBen committed Mar 23, 2017
1 parent a68ffb5 commit c6c9771
Show file tree
Hide file tree
Showing 18 changed files with 403 additions and 364 deletions.
1 change: 1 addition & 0 deletions app/controllers/api/v1/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module V1
class PasswordsController < DeviseTokenAuth::PasswordsController
protect_from_forgery with: :exception
include Concerns::ActAsApiRequest
skip_before_action :check_json_request, on: :edit
end
end
end
101 changes: 0 additions & 101 deletions spec/controllers/api/v1/passwords_controller_spec.rb

This file was deleted.

165 changes: 0 additions & 165 deletions spec/controllers/api/v1/sessions_controller_spec.rb

This file was deleted.

67 changes: 0 additions & 67 deletions spec/controllers/api/v1/users_controller_spec.rb

This file was deleted.

7 changes: 3 additions & 4 deletions spec/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ module Helpers
# Helper method to parse a response
#
# @return [Hash]
def parsed_response
def json
JSON.parse(response.body).with_indifferent_access
end

def auth_request(user)
sign_in user
request.headers.merge!(user.create_new_auth_token)
def auth_headers
user.create_new_auth_token
end
end
38 changes: 38 additions & 0 deletions spec/requests/api/v1/passwords/create_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'rails_helper'

describe 'POST api/v1/users/passwords', type: :request do
let!(:user) { create(:user, password: 'mypass123') }

before :each do
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
end

context 'with valid params' do
let(:params) { { email: user.email } }

it 'returns a successful response' do
post user_password_path, params: params, as: :json
expect(response).to have_http_status(:success)
end

it 'sends an email' do
expect { post user_password_path, params: params, as: :json }
.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end

context 'with invalid params' do
it 'does not return a successful response' do
post user_password_path, params: { email: 'notvalid@example.com' }, as: :json
expect(response.status).to eq(404)
end

it 'does not send an email' do
expect do
post user_password_path, params: { email: 'notvalid@example.com' }, as: :json
end.to change { ActionMailer::Base.deliveries.count }.by(0)
end
end
end
Loading

0 comments on commit c6c9771

Please sign in to comment.