diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index 06a8041b..0722fe94 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -21,6 +21,7 @@ def index
# GET /courses/1.json
def show
@reviews = @course.reviews.preload(:user, course: [:school])
+ @url = school_course_reviews_path(school_id: @school, course_id: @course)
end
# GET /courses/new
diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb
index 7f48851c..cab06940 100644
--- a/app/controllers/reviews_controller.rb
+++ b/app/controllers/reviews_controller.rb
@@ -12,7 +12,7 @@ class ReviewsController < ApplicationController
def index
if params[:course_id].to_i.zero?
if params[:school_id].to_i.zero?
- @reviews = Review.all
+ @reviews = Review.preload(:user, course: [:school]).all
else
set_school
@reviews = Review.preload(:user, course: [:school]).joins(:course).where('courses.school_id = (?)', @school.id)
@@ -42,6 +42,7 @@ def edit
# POST /schools/1/courses/1/reviews
# POST /schools/1/courses/1/reviews.json
def create
+ @url = school_course_reviews_path
@review = Review.new(review_params)
respond_to do |format|
if @review.save
@@ -83,7 +84,11 @@ def update
def destroy
@review.destroy
respond_to do |format|
- format.html { redirect_to school_course_reviews_url, notice: 'Review was successfully destroyed.' }
+ format.html do
+ redirect_to school_course_reviews_url(school_id: @school,
+ course_id: @course),
+ notice: 'Review was successfully destroyed.'
+ end
format.json { head :no_content }
end
end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 0dbf9b8a..3e7257e2 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -59,7 +59,7 @@ def destroy
# PUT /users/1/promote
def promote
@user.update(is_admin: true)
- redirect_to users_url, notice: "#{@user.email} was successfully demoted from admin."
+ redirect_to users_url, notice: "#{@user.email} was successfully promoted to admin."
end
# PUT /users/1/demote
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 4e15fb81..5b11a2ee 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -15,7 +15,7 @@ def initialize(user)
can [:update, :delete], Review do |r|
r.user == user
end
- can [:update, :delete], User do |u|
+ can [:read, :update, :delete], User do |u|
u == user
end
return unless user.admin?
diff --git a/app/views/courses/edit.html.erb b/app/views/courses/edit.html.erb
index 2d2f4231..fbd7d050 100644
--- a/app/views/courses/edit.html.erb
+++ b/app/views/courses/edit.html.erb
@@ -2,4 +2,4 @@
<%= render 'form', course: @course %>
-<%= link_to 'Show', school_course_path(school_id: @school.id, id: @course.id) %> |
+<%= link_to 'Show', school_course_path(school_id: @school.id, id: @course.id) %>
diff --git a/app/views/courses/index.html.erb b/app/views/courses/index.html.erb
index eb4d5920..3b0fecf1 100644
--- a/app/views/courses/index.html.erb
+++ b/app/views/courses/index.html.erb
@@ -1,5 +1,3 @@
-
<%= notice %>
-
Courses
<% if can? :create, Course %>
<% if @school %>
@@ -8,30 +6,34 @@
<%= link_to 'Select a school first to add a new course', schools_path %>
<% end %>
<% end %>
-
-
-
-
- Name |
- Number |
- Department |
- School |
- |
-
-
-
-
- <% @courses.each do |course| %>
+
+<% if @courses.load.empty? %>
+ No courses at this time!
+<% else %>
+
+
- <%= link_to course.name, school_course_path(id: course.id, school_id: course.school.id) %> |
- <%= course.number %> |
- <%= course.department %> |
- <%= link_to course.school.name, school_path(id: course.school) %> |
- <% if can? :edit, course %>
- | <%= link_to 'Edit', edit_school_course_path(id: course.id, school_id: course.school.id) %> |
- <%= link_to 'Destroy', school_course_path(id: course.id, school_id: course.school.id), method: :delete, data: { confirm: 'Are you sure?' } %> |
- <% end %>
+ Name |
+ Number |
+ Department |
+ School |
+ |
- <% end %>
-
-
+
+
+
+ <% @courses.each do |course| %>
+
+ <%= link_to course.name, school_course_path(id: course.id, school_id: course.school.id) %> |
+ <%= course.number %> |
+ <%= course.department %> |
+ <%= link_to course.school.name, school_path(id: course.school) %> |
+ <% if can? :edit, course %>
+ | <%= link_to 'Edit', edit_school_course_path(id: course.id, school_id: course.school.id) %> |
+ <%= link_to 'Destroy', school_course_path(id: course.id, school_id: course.school.id), method: :delete, data: { confirm: 'Are you sure?' } %> |
+ <% end %>
+
+ <% end %>
+
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/courses/show.html.erb b/app/views/courses/show.html.erb
index e9952861..133808f9 100644
--- a/app/views/courses/show.html.erb
+++ b/app/views/courses/show.html.erb
@@ -1,7 +1,7 @@
<%= @course.name %> at <%= link_to @course.school.name, @course.school %>
<% if can? :edit, @course %>
-<%= link_to 'Edit', edit_school_course_path(@course) %>
+<%= link_to 'Edit', edit_school_course_path(school_id: @school.id, course_id: @course.id) %>
<% end %>
Number:
@@ -15,6 +15,9 @@
Reviews
- <%= link_to 'New Review', new_school_course_review_path(school_id: @school.id, course_id: @course.id) %>
+ <% if can? :create, Review %>
+ <%= link_to 'New Review', new_school_course_review_path(school_id: @school.id, course_id: @course.id) %>
+ <% end %>
+
<%= render 'reviews/review_index', reviews: @reviews %>
diff --git a/app/views/reviews/_review_index.html.erb b/app/views/reviews/_review_index.html.erb
index 6bdc9658..c876dc92 100644
--- a/app/views/reviews/_review_index.html.erb
+++ b/app/views/reviews/_review_index.html.erb
@@ -1,4 +1,4 @@
-<% if reviews.empty? %>
+<% if reviews.load.empty? %>
No reviews at this time!
<% else %>
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb
index b3977005..1178ae26 100644
--- a/app/views/users/index.html.erb
+++ b/app/views/users/index.html.erb
@@ -1,7 +1,6 @@
-<%= notice %>
-
-Users
-
+<% if can? :manage, User %>
+Users
@@ -29,7 +28,4 @@
<% end %>
-
-
-
-<%= link_to 'New User', new_user_path %>
+<% end %>
\ No newline at end of file
diff --git a/coverage/.resultset.json b/coverage/.resultset.json
index ff00e34d..5598cac1 100644
--- a/coverage/.resultset.json
+++ b/coverage/.resultset.json
@@ -120,6 +120,7 @@
null,
1,
2,
+ 2,
null,
null,
null,
@@ -251,6 +252,7 @@
5,
5,
5,
+ 5,
2,
2,
null,
@@ -413,7 +415,7 @@
null,
null,
1,
- 4,
+ 5,
null,
null,
null,
@@ -664,6 +666,6 @@
null
]
},
- "timestamp": 1559940230
+ "timestamp": 1560033163
}
}
diff --git a/coverage/index.html b/coverage/index.html
index ed1339f9..023460f5 100644
--- a/coverage/index.html
+++ b/coverage/index.html
@@ -14,7 +14,7 @@
-
Generated
2019-06-07T16:43:50-04:00
+
Generated
2019-06-08T18:32:43-04:00
@@ -25,15 +25,15 @@
covered at
- 7.48
+ 7.45
hits/line)
17 files in total.
- 241 relevant lines.
- 241 lines covered and
+ 243 relevant lines.
+ 243 lines covered and
0 lines missed
@@ -63,9 +63,9 @@
app/controllers/courses_controller.rb |
100.0 % |
- 98 |
- 46 |
- 46 |
+ 99 |
+ 47 |
+ 47 |
0 |
3.4 |
@@ -73,9 +73,9 @@
app/controllers/reviews_controller.rb |
100.0 % |
- 119 |
- 52 |
- 52 |
+ 120 |
+ 53 |
+ 53 |
0 |
3.6 |
@@ -240,8 +240,8 @@
5 files in total.
- 173 relevant lines.
- 173 lines covered and
+ 175 relevant lines.
+ 175 lines covered and
0 lines missed
@@ -271,9 +271,9 @@
app/controllers/courses_controller.rb |
100.0 % |
- 98 |
- 46 |
- 46 |
+ 99 |
+ 47 |
+ 47 |
0 |
3.4 |
@@ -281,9 +281,9 @@
app/controllers/reviews_controller.rb |
100.0 % |
- 119 |
- 52 |
- 52 |
+ 120 |
+ 53 |
+ 53 |
0 |
3.6 |
@@ -682,8 +682,8 @@ 100.0 % covered
app/controllers/courses_controller.rb
100.0 % covered
- 46 relevant lines.
- 46 lines covered and
+ 47 relevant lines.
+ 47 lines covered and
0 lines missed.
@@ -829,451 +829,457 @@ 100.0 % covered
@reviews = @course.reviews.preload(:user, course: [:school])
-
+
+ 2
+
+ @url = school_course_reviews_path(school_id: @school, course_id: @course)
+
+
+
end
-
+
-
+
# GET /courses/new
-
+
1
def new
-
+
2
@course = Course.new
-
+
2
@url = school_courses_path
-
+
end
-
+
-
+
# GET /courses/1/edit
-
+
1
def edit
-
+
2
@url = school_course_path
-
+
end
-
+
-
+
# POST /courses
-
+
# POST /courses.json
-
+
1
def create
-
+
5
@course = Course.new(course_params)
-
+
-
+
5
respond_to do |format|
-
+
5
if @course.save
-
+
2
format.html do
-
+
2
redirect_to school_course_url(school_id: @school.id, id: @course.id),
-
+
notice: 'Course was successfully created.'
-
+
end
-
+
2
format.json { render :show, status: :created, location: @course }
-
+
else
-
+
6
format.html { render :new }
-
+
3
format.json { render json: @course.errors, status: :unprocessable_entity }
-
+
end
-
+
end
-
+
end
-
+
-
+
# PATCH/PUT /courses/1
-
+
# PATCH/PUT /courses/1.json
-
+
1
def update
-
+
4
respond_to do |format|
-
+
4
if @course.update(course_params)
-
+
3
format.html do
-
+
3
redirect_to school_course_url(school_id: @school.id, id: @course.id),
-
+
notice: 'Course was successfully updated.'
-
+
end
-
+
3
format.json { render :show, status: :ok, location: @course }
-
+
else
-
+
2
format.html { render :edit }
-
+
1
format.json { render json: @course.errors, status: :unprocessable_entity }
-
+
end
-
+
end
-
+
end
-
+
-
+
# DELETE /courses/1
-
+
# DELETE /courses/1.json
-
+
1
def destroy
-
+
2
@course.destroy
-
+
2
respond_to do |format|
-
+
4
format.html { redirect_to school_courses_url, notice: 'Course was successfully destroyed.' }
-
+
2
format.json { head :no_content }
-
+
end
-
+
end
-
+
-
+
1
private
-
+
-
+
# Use callbacks to share common setup or constraints between actions.
-
+
1
def set_school
-
+
26
@school = School.find(params[:school_id])
-
+
end
-
+
-
+
1
def set_course
-
+
10
@course = Course.find(params[:id])
-
+
end
-
+
-
+
# Never trust parameters from the scary internet, only allow the white list through.
-
+
1
def course_params
-
+
14
params.require(:course).permit(:name, :number, :department, :school_id)
-
+
end
-
+
end
@@ -1289,8 +1295,8 @@ 100.0 % covered
app/controllers/reviews_controller.rb
100.0 % covered
- 52 relevant lines.
- 52 lines covered and
+ 53 relevant lines.
+ 53 lines covered and
0 lines missed.
@@ -1385,7 +1391,7 @@ 100.0 % covered
1
- @reviews = Review.all
+ @reviews = Review.preload(:user, course: [:school]).all
@@ -1565,448 +1571,454 @@ 100.0 % covered
5
- @review = Review.new(review_params)
+ @url = school_course_reviews_path
5
- respond_to do |format|
+ @review = Review.new(review_params)
5
+ respond_to do |format|
+
+
+
+ 5
+
if @review.save
-
+
2
format.html do
-
+
2
redirect_to school_course_review_url(school_id: @school.id,
-
+
course_id: @course.id,
-
+
id: @review.id),
-
+
notice: 'Review was successfully created.'
-
+
end
-
+
2
format.json { render :show, status: :created, location: @review }
-
+
else
-
+
6
format.html { render :new }
-
+
3
format.json { render json: @review.errors, status: :unprocessable_entity }
-
+
end
-
+
end
-
+
end
-
+
-
+
# PATCH/PUT /schools/1/courses/1/reviews/1
-
+
# PATCH/PUT /schools/1/courses/1/reviews/1.json
-
+
1
def update
-
+
4
respond_to do |format|
-
+
4
if @review.update(review_params)
-
+
2
format.html do
-
+
2
redirect_to school_course_review_url(school_id: @school.id,
-
+
course_id: @course.id,
-
+
id: @review.id),
-
+
notice: 'Review was successfully updated.'
-
+
end
-
+
2
format.json { render :show, status: :ok, location: @review }
-
+
else
-
+
4
format.html { render :edit }
-
+
2
format.json { render json: @review.errors, status: :unprocessable_entity }
-
+
end
-
+
end
-
+
end
-
+
-
+
# DELETE /schools/1/courses/1/reviews/1
-
+
# DELETE /schools/1/courses/1/reviews/1.json
-
+
1
def destroy
-
+
2
@review.destroy
-
+
2
respond_to do |format|
-
+
4
- format.html { redirect_to school_course_reviews_url, notice: 'Review was successfully destroyed.' }
+ format.html { redirect_to school_course_reviews_url(school_id: @school, course_id: @course), notice: 'Review was successfully destroyed.' }
-
+
2
format.json { head :no_content }
-
+
end
-
+
end
-
+
-
+
1
private
-
+
-
+
# Use callbacks to share common setup or constraints between actions.
-
+
1
def set_school
-
+
25
@school = School.find(params[:school_id])
-
+
end
-
+
-
+
1
def set_course
-
+
24
@course = Course.find(params[:course_id])
-
+
end
-
+
-
+
1
def set_review
-
+
11
@review = Review.find(params[:id])
-
+
end
-
+
-
+
# Never trust parameters from the scary internet, only allow the white list through.
-
+
1
def review_params
-
+
14
params.require(:review).permit(:course_id,
-
+
:user_id,
-
+
:notes,
-
+
:work_required,
-
+
:difficulty,
-
+
:rating,
-
+
:experience_with_topic,
-
+
:year,
-
+
:term,
-
+
:grade)
-
+
end
-
+
end
@@ -2566,8 +2578,8 @@ 100.0 % covered
def index
-
- 4
+
+ 5
@users = User.all
@@ -2875,7 +2887,7 @@ 100.0 % covered
2
- redirect_to users_url, notice: "#{@user.email} was successfully demoted from admin."
+ redirect_to users_url, notice: "#{@user.email} was successfully promoted to admin."
@@ -3398,7 +3410,7 @@ 100.0 % covered
95
- can [:update, :delete], User do |u|
+ can [:read, :update, :delete], User do |u|
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb
index f62d38b3..0ec8d600 100644
--- a/spec/controllers/users_controller_spec.rb
+++ b/spec/controllers/users_controller_spec.rb
@@ -220,8 +220,8 @@
end
describe 'GET #index' do
- it 'returns an access denied' do
- expect { get :index }.to raise_error(CanCan::AccessDenied)
+ it 'returns no errors' do
+ expect { get :index }.not_to raise_error
end
end