Skip to content

Commit

Permalink
Merge pull request #115 from jmkoni/add-teacher
Browse files Browse the repository at this point in the history
add teacher and also switch to font awesome kit
  • Loading branch information
jmkoni authored Jul 28, 2019
2 parents 85f5e17 + 9ea36c5 commit 6bf66b2
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 17 deletions.
3 changes: 2 additions & 1 deletion app/controllers/reviews_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def review_params
:experience_with_topic,
:year,
:term,
:grade)
:grade,
:teacher)
end
end
13 changes: 9 additions & 4 deletions app/models/review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ class Review < ApplicationRecord
# configure number of OR conditions for provision
# of interpolation arguments. Adjust this if you
# change the number of OR conditions.
num_or_conditions = 4
num_or_conditions = 5
joins(course: :department).where(
terms.map do
or_clauses = [
'LOWER(reviews.notes) LIKE ?',
'LOWER(departments.name) LIKE ?',
'LOWER(courses.name) LIKE ?',
'LOWER(courses.number) LIKE ?'
'LOWER(courses.number) LIKE ?',
'LOWER(reviews.teacher) LIKE ?'
].join(' OR ')
"(#{or_clauses})"
end.join(' AND '),
Expand All @@ -67,6 +68,8 @@ class Review < ApplicationRecord
order(Arel.sql("LOWER(departments.name) #{direction}")).includes(course: [:department]).references(:course)
when /^school_/
order(Arel.sql("LOWER(schools.name) #{direction}")).includes(course: { department: :school }).references(:course)
when /^teacher_/
order(Arel.sql("LOWER(reviews.teacher) #{direction}"))
when /^difficulty_/
order(Arel.sql("reviews.difficulty #{direction}"))
when /^rating_/
Expand Down Expand Up @@ -111,9 +114,10 @@ def self.options_for_sorted_by
['Difficulty (highest first)', 'difficulty_desc'],
['Work Required (lowest first)', 'work_required_asc'],
['Work Required (highest first)', 'work_required_desc'],
['Course (a-z)', 'department_name_asc'],
['Department (a-z)', 'department_name_asc'],
['Course (a-z)', 'course_name_asc'],
['School (a-z)', 'school_name_asc']
['School (a-z)', 'school_name_asc'],
['Teacher (a-z)', 'teacher_name_asc']
]
end

Expand Down Expand Up @@ -149,6 +153,7 @@ def display_grade
# grade :integer
# notes :string
# rating :integer
# teacher :string
# term :integer
# work_required :integer
# year :integer
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.9.0/css/all.css" integrity="sha384-vlOMx0hKjUCl4WzuhIhSNZSm2yQCaf0mOU1hEDK/iztH3gU4v5NMmJln9273A6Jz" crossorigin="anonymous" />
<script src="https://kit.fontawesome.com/7286a15af5.js"></script>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
Expand Down
6 changes: 6 additions & 0 deletions app/views/reviews/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
<%= form.number_field :grade, in: 0..100, class: "form-control" %>
<small class='form-text text-muted'>(between 0 and 100)</small>
</div>

<div class="form-group col-md-2">
<%= form.label :teacher %>
<%= form.text_field :teacher, class: "form-control" %>
<small class='form-text text-muted'>(full name of teacher for the class)</small>
</div>
</div>
<div class="actions">
<%= form.submit 'Submit', class: 'btn btn-primary' %>
Expand Down
5 changes: 5 additions & 0 deletions app/views/reviews/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<th scope="col"><%= filterrific_sorting_link(@filterrific, :course) %><button class="pull-right btn btn-default btn-condensed hide-column" data-toggle="tooltip" data-placement="bottom" title="Hide Column">
<small><i class="fal fa-eye-slash"></i></small>
</button></th>
<th scope="col"><%= filterrific_sorting_link(@filterrific, :teacher) %><button class="pull-right btn btn-default btn-condensed hide-column" data-toggle="tooltip" data-placement="bottom" title="Hide Column">
<small><i class="fal fa-eye-slash"></i></small>
</button>
</th>
<th scope="col"><%= filterrific_sorting_link(@filterrific, :user) %><button class="pull-right btn btn-default btn-condensed hide-column" data-toggle="tooltip" data-placement="bottom" title="Hide Column">
<small><i class="fal fa-eye-slash"></i></small>
</button></th>
Expand Down Expand Up @@ -73,6 +77,7 @@
<td scope="row"><%= link_to review.course.department.school.name, school_path(id: review.course.department.school.id) %></td>
<td scope="row"><%= link_to review.course.department.name, school_department_path(school_id: review.course.department.school.id, id: review.course.department.id) %></td>
<td scope="row"><%= link_to "#{review.course.name} (#{review.course.full_number})", school_department_course_path(school_id: review.course.department.school.id, department_id: review.course.department.id, id: review.course.id) %></td>
<td><%= review.teacher %></td>
<td class="user truncate"><div><%= review.user.uuid %></div></td>
<td class="notes truncate"><div><%= link_to 'Full Notes', school_department_course_review_path(school_id: review.course.department.school.id, department_id: review.course.department.id, course_id: review.course_id, id: review.id) %><%= ": " + review.notes %></div></td>
<td><%= review.rating %></td>
Expand Down
5 changes: 5 additions & 0 deletions app/views/reviews/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<%= link_to @review.course.full_number, school_department_course_path(school_id: @school.id, department_id: @department.id, id: @course.id) %>
</p>

<p>
<strong>Teacher:</strong>
<%= @review.teacher %>
</p>

<p>
<strong>User:</strong>
<%= @review.user.uuid %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20190728135222_add_prof_to_review.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddProfToReview < ActiveRecord::Migration[5.2]
def change
add_column :reviews, :teacher, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_06_26_130812) do
ActiveRecord::Schema.define(version: 2019_07_28_135222) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -45,6 +45,7 @@
t.integer "grade"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "teacher"
t.index ["course_id"], name: "index_reviews_on_course_id"
t.index ["user_id"], name: "index_reviews_on_user_id"
end
Expand Down
Binary file modified erd.pdf
Binary file not shown.
27 changes: 22 additions & 5 deletions spec/controllers/reviews_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,16 @@
expect(response).to redirect_to school_department_course_review_url(school_id: school.id, department_id: department.id, course_id: course.id, id: last_review.id)
end

it 'assigns the new review to review' do
it 'assigns the new review to review and have the correct values' do
post :create, params: { school_id: school.id, department_id: department.id, course_id: course.id, review: valid_attributes.merge(user_id: current_user.id) }
expect(assigns(:review)).to be_a_kind_of(Review)
aggregate_failures do
expect(assigns(:review)).to be_a_kind_of(Review)
expect(assigns(:review).teacher).to eq valid_attributes[:teacher]
expect(assigns(:review).grade).to eq valid_attributes[:grade]
expect(assigns(:review).rating).to eq valid_attributes[:rating]
expect(assigns(:review).notes).to eq valid_attributes[:notes]
expect(assigns(:review).work_required).to eq valid_attributes[:work_required]
end
end
end

Expand Down Expand Up @@ -236,9 +243,19 @@
expect(response).to redirect_to school_department_course_review_url(school_id: school.id, department_id: department.id, id: review.id)
end

it 'assigns the review to review' do
put :update, params: { id: review.id, school_id: school.id, department_id: department.id, course_id: course.id, review: valid_attributes }
expect(assigns(:review)).to be_a_kind_of(Review)
it 'assigns the review to review and updated values' do
aggregate_failures do
expect(review.teacher).not_to eq valid_attributes[:teacher]
put :update, params: { id: review.id, school_id: school.id, department_id: department.id, course_id: course.id, review: valid_attributes }
review.reload
expect(review.teacher).to eq valid_attributes[:teacher]
expect(assigns(:review)).to be_a_kind_of(Review)
expect(assigns(:review).teacher).to eq valid_attributes[:teacher]
expect(assigns(:review).grade).to eq valid_attributes[:grade]
expect(assigns(:review).rating).to eq valid_attributes[:rating]
expect(assigns(:review).notes).to eq valid_attributes[:notes]
expect(assigns(:review).work_required).to eq valid_attributes[:work_required]
end
end
end

Expand Down
2 changes: 2 additions & 0 deletions spec/factories/reviews.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
year { rand(2000..2019) }
term { rand(4) }
grade { rand(100) }
teacher { Faker::Name.name }
end
end

Expand All @@ -25,6 +26,7 @@
# grade :integer
# notes :string
# rating :integer
# teacher :string
# term :integer
# work_required :integer
# year :integer
Expand Down
17 changes: 12 additions & 5 deletions spec/models/review_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,25 @@
rating: 10,
work_required: 0,
grade: 100,
experience_with_topic: false)
experience_with_topic: false,
teacher: 'Zwyno')
review2 = create(:review,
notes: 'oh no',
course: course1,
difficulty: 8,
rating: 3,
work_required: 20,
grade: 50,
experience_with_topic: true)
experience_with_topic: true,
teacher: 'Ariel')
review3 = create(:review,
notes: 'bye',
difficulty: 4,
rating: 8,
work_required: 25,
grade: 85,
experience_with_topic: false)
experience_with_topic: false,
teacher: 'Bob')
aggregate_failures do
expect(Review.sorted_by('user_asc').first).to eq review1
expect(Review.sorted_by('user_desc').first).to eq review3
Expand All @@ -78,6 +81,8 @@
expect(Review.sorted_by('grade_asc').first).to eq review2
expect(Review.sorted_by('grade_desc').first).to eq review1
expect(Review.sorted_by('experience_with_topic_desc').first).to eq review2
expect(Review.sorted_by('teacher_asc').first).to eq review2
expect(Review.sorted_by('teacher_desc').first).to eq review1
expect { Review.sorted_by('oh_no') }.to raise_error(ArgumentError, 'Invalid sort option: "oh_no"')
end
end
Expand Down Expand Up @@ -208,9 +213,10 @@
['Difficulty (highest first)', 'difficulty_desc'],
['Work Required (lowest first)', 'work_required_asc'],
['Work Required (highest first)', 'work_required_desc'],
['Course (a-z)', 'department_name_asc'],
['Department (a-z)', 'department_name_asc'],
['Course (a-z)', 'course_name_asc'],
['School (a-z)', 'school_name_asc']
['School (a-z)', 'school_name_asc'],
['Teacher (a-z)', 'teacher_name_asc']
]
expect(Review.options_for_sorted_by).to eq expected_result
end
Expand All @@ -228,6 +234,7 @@
# grade :integer
# notes :string
# rating :integer
# teacher :string
# term :integer
# work_required :integer
# year :integer
Expand Down

0 comments on commit 6bf66b2

Please sign in to comment.