Skip to content

Commit

Permalink
Start fixing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmfcmf committed Nov 16, 2016
1 parent 1fa4831 commit 8814b07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions spec/controllers/application_letters_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,24 @@
describe "GET #index" do
it "assigns all applications as @applications" do
application = ApplicationLetter.create! valid_attributes
get :index, session: valid_session
sign_in application.user
get :index
expect(assigns(:application_letters)).to eq([application])
end
end

describe "GET #show" do
it "assigns the requested application as @application" do
application = ApplicationLetter.create! valid_attributes
get :show, id: application.to_param, session: valid_session
sign_in application.user
get :show, id: application.to_param
expect(assigns(:application_letter)).to eq(application)
end
end

describe "GET #new" do
it "assigns a new application as @application" do
sign_in FactoryGirl.create(:user)
get :new, session: valid_session
expect(assigns(:application_letter)).to be_a_new(ApplicationLetter)
end
Expand All @@ -55,6 +58,7 @@
describe "GET #edit" do
it "assigns the requested application as @application" do
application = ApplicationLetter.create! valid_attributes
sign_in application.user
get :edit, id: application.to_param, session: valid_session
expect(assigns(:application_letter)).to eq(application)
end
Expand All @@ -63,30 +67,36 @@
describe "POST #create" do
context "with valid params" do
it "creates a new Application" do
sign_in FactoryGirl.create(:user)
expect {
post :create, application_letter: valid_attributes, session: valid_session
}.to change(ApplicationLetter, :count).by(1)
end

it "assigns a newly created application as @application" do
sign_in FactoryGirl.create(:user)
post :create, application_letter: valid_attributes, session: valid_session
expect(assigns(:application_letter)).to be_a(ApplicationLetter)
expect(assigns(:application_letter)).to be_persisted
end

it "redirects to the created application" do
sign_in FactoryGirl.create(:user)
post :create, application_letter: valid_attributes, session: valid_session
expect(response).to redirect_to(ApplicationLetter.last)
end
end

context "with invalid params" do
it "assigns a newly created but unsaved application as @application_letter" do
user = FactoryGirl.create(:user)
sign_in user
post :create, application_letter: invalid_attributes, session: valid_session
expect(assigns(:application_letter)).to be_a_new(ApplicationLetter)
expect(assigns(:application_letter)).to be_a_new(ApplicationLetter).with(:user_id => user.id)
end

it "re-renders the 'new' template" do
sign_in FactoryGirl.create(:user)
post :create, application_letter: invalid_attributes, session: valid_session
expect(response).to render_template("new")
end
Expand Down
1 change: 1 addition & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
sequence(:name) { |n| "First Last #{n}" }
email { "#{name}@example.com".downcase.tr(" ","_") }
password "test123"
role :pupil
end
end

0 comments on commit 8814b07

Please sign in to comment.