Skip to content

Instantly share code, notes, and snippets.

@salami-art
Created January 23, 2018 10:00
Show Gist options
  • Save salami-art/7a90a905aa43d2cc9728ef54a86c22d6 to your computer and use it in GitHub Desktop.
Save salami-art/7a90a905aa43d2cc9728ef54a86c22d6 to your computer and use it in GitHub Desktop.
require 'rails_helper'
RSpec.describe RegistrationController do
include Devise::Test::ControllerHelpers
describe 'POST /users for user' do
let(:user) {
{
email: "[email protected]",
password: "master-tester",
user_profile_attributes: {
name: "Tester Name",
last_name: "Tester Surname",
bitrh_date: 21.years.ago,
city_id: 1,
sex: 'M',
phone: 123456789
}
}.as_json
}
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
end
it_behaves_like 'check delivery', :create, { :user => {
email: "[email protected]",
password: "master-tester",
user_profile_attributes: {
name: "Tester Name",
last_name: "Tester Surname",
bitrh_date: 21.years.ago,
city_id: 1,
sex: 'M',
phone: 123456789
}
}.as_json}, "[email protected]"
end
end
RSpec.shared_examples "check delivery" do |action, params, recipient|
include ActiveJob::TestHelper
before do
@request.env["devise.mapping"] = Devise.mappings[:user]
clear_enqueued_jobs
end
it "sends an email to recipient: #{recipient}" do
expect { post action, params: params }.to change { enqueued_jobs.size }.by(1)
# ....
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment