diff --git a/spec/controllers/application_letters_controller_spec.rb b/spec/controllers/application_letters_controller_spec.rb index aa8b3caf..1112244a 100644 --- a/spec/controllers/application_letters_controller_spec.rb +++ b/spec/controllers/application_letters_controller_spec.rb @@ -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 diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb index f6c155cb..743dbab2 100644 --- a/spec/controllers/profiles_controller_spec.rb +++ b/spec/controllers/profiles_controller_spec.rb @@ -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 @@ -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]) @@ -43,6 +44,7 @@ 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 @@ -50,6 +52,7 @@ 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 @@ -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 @@ -66,18 +70,21 @@ 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 @@ -85,11 +92,13 @@ 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 @@ -106,6 +115,7 @@ 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]) @@ -113,12 +123,14 @@ 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 @@ -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 @@ -142,6 +156,7 @@ 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) @@ -149,6 +164,7 @@ 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 diff --git a/spec/request_helper.rb b/spec/request_helper.rb new file mode 100644 index 00000000..0b7f4202 --- /dev/null +++ b/spec/request_helper.rb @@ -0,0 +1,3 @@ +def login(user) + post_via_redirect user_session_path, 'user[email]' => user.email, 'user[password]' => user.password +end \ No newline at end of file diff --git a/spec/requests/applications_spec.rb b/spec/requests/applications_spec.rb index 6622cfb8..65ebddd7 100644 --- a/spec/requests/applications_spec.rb +++ b/spec/requests/applications_spec.rb @@ -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 diff --git a/spec/requests/profiles_spec.rb b/spec/requests/profiles_spec.rb index a8fc5cfd..f70a7962 100644 --- a/spec/requests/profiles_spec.rb +++ b/spec/requests/profiles_spec.rb @@ -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 diff --git a/spec/views/application_letters/edit.html.erb_spec.rb b/spec/views/application_letters/edit.html.erb_spec.rb index b8e48746..30ea662a 100644 --- a/spec/views/application_letters/edit.html.erb_spec.rb +++ b/spec/views/application_letters/edit.html.erb_spec.rb @@ -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 diff --git a/spec/views/application_letters/new.html.erb_spec.rb b/spec/views/application_letters/new.html.erb_spec.rb index 88644b14..b03a366a 100644 --- a/spec/views/application_letters/new.html.erb_spec.rb +++ b/spec/views/application_letters/new.html.erb_spec.rb @@ -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 diff --git a/spec/views/profiles/edit.html.erb_spec.rb b/spec/views/profiles/edit.html.erb_spec.rb index d5ed6a0f..d36bd1c5 100644 --- a/spec/views/profiles/edit.html.erb_spec.rb +++ b/spec/views/profiles/edit.html.erb_spec.rb @@ -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 diff --git a/spec/views/profiles/new.html.erb_spec.rb b/spec/views/profiles/new.html.erb_spec.rb index f9e473bd..16b12b17 100644 --- a/spec/views/profiles/new.html.erb_spec.rb +++ b/spec/views/profiles/new.html.erb_spec.rb @@ -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