Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions spec/controllers/inquiries_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
require "spec_helper"

RSpec.describe InquiriesController do
let (:test_organization) { Fabricate(:organization) }
let (:member) { Fabricate(:member, organization: test_organization) }
let (:another_member) { Fabricate(:member, organization: test_organization) }
let (:test_category) { Fabricate(:category) }
let! (:inquiry) do
let(:test_organization) { Fabricate(:organization) }
let(:member) { Fabricate(:member, organization: test_organization) }
let(:another_member) { Fabricate(:member, organization: test_organization) }
let(:test_category) { Fabricate(:category) }
let!(:inquiry) do
Fabricate(:inquiry,
user: member.user,
organization: test_organization,
category: test_category)
end

include_context "stub browser locale"

before { set_browser_locale("ca") }

describe "GET #index" do
Expand Down Expand Up @@ -40,10 +42,9 @@

describe "POST #create" do
context "with valid params" do
context "with a logged user" do
context "with a logged user" do
it "creates a new inquiry" do
login(another_member.user)

expect do
post "create", inquiry: { user: another_member.user,
category_id: test_category.id,
Expand All @@ -57,16 +58,14 @@
describe "PUT #update" do
context "with valid params" do
context "with a logged user" do
before { login(member.user) }

it "located the requested @inquiry" do
login(member.user)

put "update", id: inquiry.id, inquiry: Fabricate.to_params(:inquiry)
expect(assigns(:inquiry)).to eq(inquiry)
end

it "changes @inquiry's attributes" do
login(member.user)

put "update",
id: inquiry.id,
inquiry: Fabricate.to_params(:inquiry,
Expand All @@ -84,7 +83,7 @@
end

context "with invalid params" do
context "with a logged user" do
context "with a logged user" do
it "does not change @inquiry's attributes" do
login(member.user)

Expand All @@ -103,18 +102,16 @@
end

describe "DELETE destroy" do
before { login(member.user) }

it "toggle active field" do
login(member.user)

delete :destroy, id: inquiry.id

inquiry.reload
expect(inquiry.active).to be false
end

it "redirects to inquiries#index" do
login(member.user)

delete :destroy, id: inquiry.id
expect(response).to redirect_to inquiries_url
end
Expand Down