Load the requested post in any case and specs++
This commit is contained in:
@ -61,12 +61,8 @@ class PostsController < ApplicationController
|
||||
# GET /inquiries/:id
|
||||
#
|
||||
def show
|
||||
scope = if current_user.present?
|
||||
current_organization.posts.active.of_active_members
|
||||
else
|
||||
model.all.active.of_active_members
|
||||
end
|
||||
post = scope.find params[:id]
|
||||
post = Post.active.of_active_members.find(params[:id])
|
||||
|
||||
instance_variable_set("@#{resource}", post)
|
||||
end
|
||||
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe OffersController, type: :controller do
|
||||
let(:test_organization) { Fabricate(:organization) }
|
||||
let(:member) { Fabricate(:member, organization: test_organization) }
|
||||
let(:another_member) { Fabricate(:member, organization: test_organization) }
|
||||
RSpec.describe OffersController, type: :controller do
|
||||
let(:organization) { Fabricate(:organization) }
|
||||
let(:member) { Fabricate(:member, organization: organization) }
|
||||
let(:another_member) { Fabricate(:member, organization: organization) }
|
||||
let(:yet_another_member) { Fabricate(:member) }
|
||||
let(:test_category) { Fabricate(:category) }
|
||||
let!(:offer) do
|
||||
Fabricate(:offer,
|
||||
user: member.user,
|
||||
organization: test_organization,
|
||||
organization: organization,
|
||||
category: test_category)
|
||||
end
|
||||
|
||||
@ -59,27 +59,81 @@ describe OffersController, type: :controller do
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
context "with valid params" do
|
||||
context "with a logged user" do
|
||||
before { login(another_member.user) }
|
||||
describe 'GET #show' do
|
||||
context 'when the user is logged in' do
|
||||
before { login(another_member.user) }
|
||||
|
||||
it "assigns the requested offer to @offer" do
|
||||
get :show, id: offer.id
|
||||
expect(assigns(:offer)).to eq(offer)
|
||||
context 'when the requested offer' do
|
||||
context 'is not active' do
|
||||
before do
|
||||
offer.active = false
|
||||
offer.save!
|
||||
end
|
||||
|
||||
it 'renders the 404 page' do
|
||||
get :show, id: offer.id
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
end
|
||||
|
||||
it 'assigns the account destination of the transfer' do
|
||||
get :show, id: offer.id
|
||||
expect(assigns(:destination_account)).to eq(member.account)
|
||||
context 'is active' do
|
||||
context 'and the user that created the offer is not active anymore' do
|
||||
before do
|
||||
member.active = false
|
||||
member.save!
|
||||
end
|
||||
|
||||
it 'renders the 404 page' do
|
||||
get :show, id: offer.id
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
end
|
||||
|
||||
context 'and the user that created the offer is active' do
|
||||
it 'renders a successful response' do
|
||||
get :show, id: offer.id
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it 'assigns the requested offer to @offer' do
|
||||
get :show, id: offer.id
|
||||
expect(assigns(:offer)).to eq(offer)
|
||||
end
|
||||
|
||||
it 'assigns the account destination of the transfer' do
|
||||
get :show, id: offer.id
|
||||
expect(assigns(:destination_account)).to eq(member.account)
|
||||
end
|
||||
|
||||
it 'displays the offer\'s user details' do
|
||||
get :show, id: offer.id
|
||||
expect(response.body).to include(offer.user.email)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "without a logged in user" do
|
||||
it "assigns the requested offer to @offer" do
|
||||
get :show, id: offer.id
|
||||
expect(assigns(:offer)).to eq(offer)
|
||||
end
|
||||
context 'when the user is not a member of the organization where the offer is published' do
|
||||
let(:another_user) { Fabricate(:user) }
|
||||
|
||||
before { login(another_user) }
|
||||
|
||||
it 'doesn\'t display the offer\'s user details' do
|
||||
get :show, id: offer.id
|
||||
expect(response.body).to_not include(offer.user.email)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the user is not logged in' do
|
||||
it 'assigns the requested offer to @offer' do
|
||||
get :show, id: offer.id
|
||||
expect(assigns(:offer)).to eq(offer)
|
||||
end
|
||||
|
||||
it 'doesn\'t display the offer\'s user details' do
|
||||
get :show, id: offer.id
|
||||
expect(response.body).to_not include(offer.user.email)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user