This repository has been archived by the owner on Mar 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from snap-cloud/rspec-update
Rspec update
- Loading branch information
Showing
19 changed files
with
205 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require 'spec_helper' | ||
require 'rails_helper' | ||
require 'api/v1/projects_controller' | ||
|
||
|
||
|
@@ -14,7 +14,7 @@ | |
allow(request.env['warden']).to receive(:authenticate!).and_return(fakeuser) | ||
allow(controller).to receive(:current_user).and_return(fakeuser) | ||
|
||
get :show, id: @project.id, format: :json | ||
get :show, id: @project.id | ||
end | ||
|
||
it { should respond_with 200 } | ||
|
@@ -38,14 +38,14 @@ | |
proj = Project.create(title: "Test proj", owner:user.id) | ||
Project.any_instance.should_receive(:update_attributes) | ||
Api::V1::ProjectsController.any_instance.stub(:getCurrentUser).and_return(user) | ||
put :update, { project_params: proj.attributes, id:proj.id }, format: :json | ||
put :update, { project_params: proj.attributes, id:proj.id } | ||
expect(response.status).to eq(204) | ||
end | ||
|
||
it "should reject the request when I am not logged in" do | ||
proj = Project.create(title: "Test proj") | ||
Api::V1::ProjectsController.any_instance.stub(:getCurrentUser).and_return(nil) | ||
put :update, { project_params: proj.attributes, id:proj.id}, format: :json | ||
put :update, { project_params: proj.attributes, id:proj.id} | ||
expect(response.status).to eq(401) | ||
end | ||
|
||
|
@@ -54,15 +54,15 @@ | |
not_users_id = user.id+1 | ||
proj = Project.create(title: "Test proj", owner:(not_users_id)) | ||
Api::V1::ProjectsController.any_instance.stub(:getCurrentUser).and_return(user) | ||
put :update, { project_params: proj.attributes, id:proj.id }, format: :json | ||
put :update, { project_params: proj.attributes, id:proj.id } | ||
expect(response.status).to eq(401) | ||
end | ||
|
||
it "should reject the request when the project doesn't exist" do | ||
user = User.create(email: "[email protected]") | ||
proj = Project.create(title: "Test proj", owner:user.id) | ||
Api::V1::ProjectsController.any_instance.stub(:getCurrentUser).and_return(user) | ||
put :update, { project_params: proj.attributes, id:(proj.id+1) }, format: :json | ||
put :update, { project_params: proj.attributes, id:(proj.id+1) } | ||
expect(response.status).to eq(404) | ||
end | ||
end | ||
|
@@ -83,12 +83,9 @@ | |
Api::V1::ProjectsController.any_instance.stub(:getCurrentUser).and_return(user1) | ||
|
||
post :create, {project_params: {title: "test proj for user 1", owner:user1.id}} | ||
expect(response.status).to eq(200) #:ok | ||
expect(response.status).to eq(200) | ||
end | ||
|
||
|
||
|
||
|
||
end | ||
|
||
describe "DELETE #destroy" do | ||
|
@@ -109,22 +106,19 @@ | |
Api::V1::ProjectsController.any_instance.stub(:getCurrentUser).and_return(user1) | ||
user1_proj = Project.create(title: "user1 proj", owner:user1.id) | ||
|
||
delete :destroy, {id: user1_proj.id} | ||
#project_response = JSON.parse(response.body, symbolize_names: true) | ||
## response is populated with last response; last line is unnecessary for now | ||
expect(response.status).to eq(200) #:ok | ||
delete :destroy, { id: user1_proj.id } | ||
expect(response.status).to eq(200) | ||
end | ||
|
||
it "should reject the request if user is not an owner" do | ||
user1 = User.create(email: "[email protected]") | ||
user2 = User.create(email: "[email protected]") | ||
Api::V1::ProjectsController.any_instance.stub(:getCurrentUser).and_return(user2) | ||
user1_proj = Project.create(title: "user1 proj", owner:user1.id) | ||
user1_proj = Project.create(title: "user1 proj", owner: user1.id) | ||
|
||
delete :destroy, {id: user1_proj.id} | ||
#project_response = JSON.parse(response.body, symbolize_names: true) | ||
## response is populated with last response; last line is unnecessary for now | ||
expect(response.status).to eq(401) #:unauthorized | ||
delete :destroy, { id: user1_proj.id } | ||
# FIXME -- Should probably be a 404. | ||
expect(response.status).to eq(401) | ||
end | ||
end | ||
|
||
|
@@ -148,23 +142,23 @@ | |
proj2 = Project.create(title: "user private", owner:user.id, is_public: 0) | ||
proj3 = Project.create(title: "nonuser public", owner:not_users_id, is_public: 1) | ||
proj4 = Project.create(title: "nonuser private", owner:not_users_id, is_public: 0) | ||
get :index, {user_id: user.id}, format: :json | ||
get :index, {user_id: user.id} | ||
project_response = JSON.parse(response.body, symbolize_names: true) | ||
|
||
expect(project_response.length).to eq(2) | ||
expect(project_response[0][:title]).to eq("user public") | ||
expect(project_response[1][:title]).to eq("user private") | ||
end | ||
|
||
it "Should show only public projects if user not logged in" do | ||
it "should show only public projects if user not logged in" do | ||
user = User.create(email: "[email protected]") | ||
not_users_id = user.id+1 | ||
Api::V1::ProjectsController.any_instance.stub(:getCurrentUser).and_return(nil) | ||
proj1 = Project.create(title: "user public", owner:user.id, is_public: 1) | ||
proj2 = Project.create(title: "user private", owner:user.id, is_public: 0) | ||
proj3 = Project.create(title: "nonuser public", owner:not_users_id, is_public: 1) | ||
proj4 = Project.create(title: "nonuser private", owner:not_users_id, is_public: 0) | ||
get :index, {user_id: user.id}, format: :json | ||
get :index, {user_id: user.id} | ||
project_response = JSON.parse(response.body, symbolize_names: true) | ||
expect(project_response.length).to eq(1) | ||
expect(project_response[0][:title]).to eq("user public") | ||
|
@@ -177,8 +171,7 @@ | |
# before(:each) do | ||
# @project = FactoryGirl.create :project | ||
# patch :update, { id: @project.id, | ||
# project: { title: "new title" } }, format: :json | ||
# end | ||
# project: { title: "new title" } } # end | ||
|
||
# it "renders the json representation for the updated project" do | ||
# project_response = JSON.parse(response.body, symbolize_names: true) | ||
|
@@ -192,8 +185,7 @@ | |
# before(:each) do | ||
# @project = FactoryGirl.create :project | ||
# patch :update, { id: @project.id, | ||
# project: { title: "bad title" } }, format: :json | ||
# end | ||
# project: { title: "bad title" } } # end | ||
|
||
# it "renders an errors json" do | ||
# project_response = JSON.parse(response.body, symbolize_names: true) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
require 'spec_helper' | ||
require 'rails_helper' | ||
require 'sessions_controller' | ||
require 'registrations_controller' | ||
require 'api/v1/users_controller' | ||
|
||
describe Api::V1::UsersController do | ||
|
||
before(:each) { request.headers['Accept'] = "application/json" } | ||
|
||
describe "GET #show" do | ||
|
@@ -14,7 +14,7 @@ | |
allow(controller).to receive(:current_user).and_return(fakeuser) | ||
|
||
@user = FactoryGirl.create :user | ||
get :show, id: @user.id, format: :json | ||
get :show, id: @user.id | ||
|
||
end | ||
|
||
|
@@ -35,7 +35,7 @@ | |
allow(request.env['warden']).to receive(:authenticate!).and_return(fakeuser) | ||
allow(controller).to receive(:current_user).and_return(fakeuser) | ||
|
||
post :create, { user: @user_attrs }, format: :json | ||
post :create, { user: @user_attrs } | ||
end | ||
|
||
it "renders the json representation for the user record just created" do | ||
|
@@ -57,7 +57,7 @@ | |
allow(controller).to receive(:current_user).and_return(fakeuser) | ||
|
||
|
||
post :create, { user: @invalid_user_attributes }, format: :json | ||
post :create, { user: @invalid_user_attributes } | ||
end | ||
|
||
it "renders json with errors" do | ||
|
@@ -82,11 +82,10 @@ | |
allow(request.env['warden']).to receive(:authenticate!).and_return(fakeuser) | ||
allow(controller).to receive(:current_user).and_return(fakeuser) | ||
|
||
delete :destroy, { id: @user.id }, format: :json | ||
delete :destroy, { id: @user.id } | ||
end | ||
|
||
it { should respond_with 204 } | ||
|
||
end | ||
|
||
describe "PUT/PATCH #update" do | ||
|
@@ -100,7 +99,7 @@ | |
allow(controller).to receive(:current_user).and_return(fakeuser) | ||
|
||
patch :update, { id: @user.id, | ||
user: { email: "[email protected]" } }, format: :json | ||
user: { email: "[email protected]" } } | ||
|
||
end | ||
|
||
|
@@ -121,11 +120,10 @@ | |
allow(controller).to receive(:current_user).and_return(fakeuser) | ||
|
||
|
||
patch :update, { id: @user.id, | ||
user: { email: "bademail.com" } }, format: :json | ||
patch :update, { id: @user.id, user: { email: "bademail.com" } } | ||
end | ||
|
||
it "renders an errors json" do | ||
it "rendered json with errors" do | ||
user_response = JSON.parse(response.body, symbolize_names: true) | ||
expect(user_response).to have_key(:errors) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require 'spec_helper' | ||
require 'rails_helper' | ||
|
||
describe AssignmentsController do | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
require 'spec_helper' | ||
require 'rails_helper' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require 'spec_helper' | ||
require 'rails_helper' | ||
|
||
describe ProjectsController do | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require 'spec_helper' | ||
require 'rails_helper' | ||
|
||
describe SubmissionsController do | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require 'spec_helper' | ||
require 'rails_helper' | ||
|
||
describe UsersController do | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require 'spec_helper' | ||
require 'rails_helper' | ||
|
||
describe Course do | ||
describe "#students" do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require 'spec_helper' | ||
require 'rails_helper' | ||
|
||
describe User do | ||
before { @user = FactoryGirl.build(:user) } | ||
|
Oops, something went wrong.