Skip to content

Commit

Permalink
Fixed failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrik Folkerts committed Nov 16, 2016
1 parent eb90521 commit 3f9fbb4
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion spec/controllers/application_letters_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
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).with(:user_id => user.id)
expect(assigns(:application_letter)).to be_a_new(ApplicationLetter)
end

it "re-renders the 'new' template" do
Expand Down
18 changes: 17 additions & 1 deletion spec/controllers/profiles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# adjust the attributes here as well.
let(:valid_attributes) { FactoryGirl.build(:profile).attributes }

let(:invalid_attributes) { FactoryGirl.build(:profile, user: nil).attributes }
let(:invalid_attributes) { FactoryGirl.build(:profile, user: nil).attributes } #TODO: we need another required field for a profile

# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
Expand All @@ -34,6 +34,7 @@

describe "GET #index" do
it "assigns all profiles as @profiles" do
sign_in FactoryGirl.create(:user)
profile = Profile.create! valid_attributes
get :index, params: {}, session: valid_session
expect(assigns(:profiles)).to eq([profile])
Expand All @@ -43,13 +44,15 @@
describe "GET #show" do
it "assigns the requested profile as @profile" do
profile = Profile.create! valid_attributes
sign_in profile.user
get :show, id: profile.to_param, session: valid_session
expect(assigns(:profile)).to eq(profile)
end
end

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

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

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

context "with invalid params" do
it "assigns a newly created but unsaved profile as @profile" do
sign_in FactoryGirl.create(:user)
post :create, profile: invalid_attributes, session: valid_session
expect(assigns(:profile)).to be_a_new(Profile)
end

it "re-renders the 'new' template" do
sign_in FactoryGirl.create(:user)
post :create, profile: invalid_attributes, session: valid_session
expect(response).to render_template("new")
end
Expand All @@ -106,19 +115,22 @@

it "updates the requested profile" do
profile = Profile.create! valid_attributes
sign_in profile.user
put :update, id: profile.to_param, profile: new_attributes, session: valid_session
profile.reload
expect(profile.cv).to eq(new_attributes[:cv])
end

it "assigns the requested profile as @profile" do
profile = Profile.create! valid_attributes
sign_in profile.user
put :update, id: profile.to_param, profile: valid_attributes, session: valid_session
expect(assigns(:profile)).to eq(profile)
end

it "redirects to the profile" do
profile = Profile.create! valid_attributes
sign_in profile.user
put :update, id: profile.to_param, profile: valid_attributes, session: valid_session
expect(response).to redirect_to(profile)
end
Expand All @@ -127,12 +139,14 @@
context "with invalid params" do
it "assigns the profile as @profile" do
profile = Profile.create! valid_attributes
sign_in profile.user
put :update, id: profile.to_param, profile: invalid_attributes, session: valid_session
expect(assigns(:profile)).to eq(profile)
end

it "re-renders the 'edit' template" do
profile = Profile.create! valid_attributes
sign_in profile.user
put :update, id: profile.to_param, profile: invalid_attributes, session: valid_session
expect(response).to render_template("edit")
end
Expand All @@ -142,13 +156,15 @@
describe "DELETE #destroy" do
it "destroys the requested profile" do
profile = Profile.create! valid_attributes
sign_in profile.user
expect {
delete :destroy, id: profile.to_param, session: valid_session
}.to change(Profile, :count).by(-1)
end

it "redirects to the profiles list" do
profile = Profile.create! valid_attributes
sign_in profile.user
delete :destroy, id: profile.to_param, session: valid_session
expect(response).to redirect_to(profiles_url)
end
Expand Down
3 changes: 3 additions & 0 deletions spec/request_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def login(user)
post_via_redirect user_session_path, 'user[email]' => user.email, 'user[password]' => user.password
end
2 changes: 2 additions & 0 deletions spec/requests/applications_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require 'rails_helper'
require 'request_helper'

RSpec.describe "Applications", type: :request do
describe "GET /applications" do
it "works! (now write some real specs)" do
login FactoryGirl.create(:user)
get application_letters_path
expect(response).to have_http_status(200)
end
Expand Down
2 changes: 2 additions & 0 deletions spec/requests/profiles_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
require 'rails_helper'
require 'request_helper'

RSpec.describe "Profiles", type: :request do
describe "GET /profiles" do
it "works! (now write some real specs)" do
login FactoryGirl.create(:user)
get profiles_path
expect(response).to have_http_status(200)
end
Expand Down
1 change: 0 additions & 1 deletion spec/views/application_letters/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

assert_select "form[action=?][method=?]", application_letter_path(@application_letter), "post" do
assert_select "input#application_letter_motivation[name=?]", "application_letter[motivation]"
assert_select "input#application_letter_user_id[name=?]", "application_letter[user_id]"
assert_select "input#application_letter_workshop_id[name=?]", "application_letter[workshop_id]"
end
end
Expand Down
1 change: 0 additions & 1 deletion spec/views/application_letters/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

assert_select "form[action=?][method=?]", application_letters_path, "post" do
assert_select "input#application_letter_motivation[name=?]", "application_letter[motivation]"
assert_select "input#application_letter_user_id[name=?]", "application_letter[user_id]"
assert_select "input#application_letter_workshop_id[name=?]", "application_letter[workshop_id]"
end
end
Expand Down
1 change: 0 additions & 1 deletion spec/views/profiles/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

assert_select "form[action=?][method=?]", profile_path(@profile), "post" do
assert_select "input#profile_cv[name=?]", "profile[cv]"
assert_select "input#profile_user_id[name=?]", "profile[user_id]"
end
end
end
1 change: 0 additions & 1 deletion spec/views/profiles/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

assert_select "form[action=?][method=?]", profiles_path, "post" do
assert_select "input#profile_cv[name=?]", "profile[cv]"
assert_select "input#profile_user_id[name=?]", "profile[user_id]"
end
end
end

0 comments on commit 3f9fbb4

Please sign in to comment.