Move create test into a describe block

This commit is contained in:
Karina Kwiatek 2023-01-02 09:15:51 +01:00
parent 0f01177c67
commit f80d4ce935
1 changed files with 32 additions and 30 deletions

View File

@ -3,45 +3,47 @@
require "rails_helper" require "rails_helper"
describe ServicesController, type: :controller do describe ServicesController, type: :controller do
context "successful Twitter sign in" do describe "#create" do
let(:user) { FactoryBot.create(:user) }
before do
sign_in user
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:twitter] = OmniAuth::AuthHash.new({
"provider" => "twitter",
"uid" => "12",
"info" => { "nickname" => "jack" },
"credentials" => { "token" => "AAAA", "secret" => "BBBB" }
})
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:twitter]
end
after do
OmniAuth.config.mock_auth[:twitter] = nil
end
subject { get :create, params: { provider: "twitter" } } subject { get :create, params: { provider: "twitter" } }
context "no services connected" do context "successful Twitter sign in" do
it "creates a service integration" do let(:user) { FactoryBot.create(:user) }
expect { subject }.to change { Service.count }.by(1)
before do
sign_in user
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:twitter] = OmniAuth::AuthHash.new({
"provider" => "twitter",
"uid" => "12",
"info" => { "nickname" => "jack" },
"credentials" => { "token" => "AAAA", "secret" => "BBBB" }
})
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:twitter]
end end
end
context "a user has a service connected" do after do
let(:other_user) { FactoryBot.create(:user) } OmniAuth.config.mock_auth[:twitter] = nil
let!(:service) { Services::Twitter.create(user: other_user, uid: 12) } end
it "shows an error when trying to attach a service account which is already connected" do context "no services connected" do
subject it "creates a service integration" do
expect(flash[:error]).to eq("The Twitter account you are trying to connect is already connected to another #{APP_CONFIG['site_name']} account. If you are unable to disconnect the account yourself, please send us a Direct Message on Twitter: @retrospring.") expect { subject }.to change { Service.count }.by(1)
end
end
context "a user has a service connected" do
let(:other_user) { FactoryBot.create(:user) }
let!(:service) { Services::Twitter.create(user: other_user, uid: 12) }
it "shows an error when trying to attach a service account which is already connected" do
subject
expect(flash[:error]).to eq("The Twitter account you are trying to connect is already connected to another #{APP_CONFIG['site_name']} account. If you are unable to disconnect the account yourself, please send us a Direct Message on Twitter: @retrospring.")
end
end end
end end
end end
context "#update" do describe "#update" do
subject { patch :update, params: } subject { patch :update, params: }
context "not signed in" do context "not signed in" do