Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added controller specs #772

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
59 changes: 59 additions & 0 deletions spec/controllers/members/comments_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require "spec_helper"

describe Members::CommentsController do
include AuthHelper

let(:member) { create :member }
let(:application) { create :application }

describe "GET index" do
subject { get :index }

it_should_behave_like "deny non-members", [:visitor, :applicant]
it_should_behave_like "allow members", [:member, :voting_member]
end

describe "POST create" do
subject { post :create, params: params }

it_should_behave_like "deny non-members", [:visitor, :applicant]

context "when logged in as a member" do
before do
login_as(member)
end

context "with a valid comment" do
let(:params) {
{
comment: {application_id: application.id, body: "test body"},
application_id: application.id,
user_id: member.id
}
}

it "creates a comment" do
subject
expect(Comment.last.application_id).to eq application.id
expect(Comment.last.user_id).to eq member.id
expect(Comment.last.body).to eq "test body"
end
end

context "with an invalid comment" do
let(:params) {
{
comment: {application_id: application.id, body: nil},
application_id: application.id,
user_id: member.id
}
}

it "does not create a comment" do
subject
expect(Comment.last).to be_nil
end
end
end
end
end