From 0d955f8c9918438e7cb2607e38286497bc296e4d Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Tue, 21 Apr 2015 23:48:59 -0700 Subject: [PATCH 1/2] Fix so projects doesnt 404 when it shouldnt --- app/controllers/projects_controller.rb | 10 +++++----- config/routes.rb | 7 +++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 44a672d..35e90e3 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -10,13 +10,13 @@ def index if @project render :action => "show" end - + # TODO: Show interesting Public Projects end def show # @project = find_project() if @project != nil - @project = Project.find(params[:id]) + # @project = Project.find(params[:id]) @owner = User.find_by_id @project.owner render :action => "show" end @@ -57,11 +57,11 @@ def destroy private def find_project + @project = nil if params[:username] && params[:projectname] find_project_by_name(params[:username], params[:projectname]) - elsif not Project.exists?(params[:id]) - item_not_found - else + elsif params[:id] + # AR will automatically throw a not found exception @project = Project.find(params[:id]) end end diff --git a/config/routes.rb b/config/routes.rb index 7ac8172..4afb75c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,11 +17,14 @@ # viewable project mappings resources :projects #, :only => [:show] # , :new, :create - resources :users + resources :users do + resources :projects + end + get 'assignments/:course_id/new', to: 'assignments#new', as: 'assignment_new' - post 'assignments/:course_id/create', to: 'assignments#create', as: 'assignment_create' + post 'assignments/:course_id/create', to: 'assignments#create', as: 'assignment_create' post 'assignments/:id/update', to: 'assignments#update', as: 'assignment_update' post 'assignments/:id/delete', to: 'assignments#delete', as: 'assignment_delete' get 'assignments/:id/edit', to: 'assignments#edit', as: 'assignment_edit' From b9ac374e67d1dbcc2db53cb531e0ed60072032bb Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Tue, 21 Apr 2015 23:50:59 -0700 Subject: [PATCH 2/2] cleanup debugger code...oops --- app/controllers/api/v1/projects_controller.rb | 1 - spec/controllers/api/v1/projects_controller_spec.rb | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index a07d448..88ea3e5 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -10,7 +10,6 @@ def show # returns all projects if user is looking at own projects # returns public projects for users if otherwise def index - # find_project if @project respond_with @project return diff --git a/spec/controllers/api/v1/projects_controller_spec.rb b/spec/controllers/api/v1/projects_controller_spec.rb index 99097ba..d6d9d4b 100644 --- a/spec/controllers/api/v1/projects_controller_spec.rb +++ b/spec/controllers/api/v1/projects_controller_spec.rb @@ -150,6 +150,7 @@ proj4 = Project.create(title: "nonuser private", owner:not_users_id, is_public: 0) get :index, {user_id: user.id}, format: :json 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")