diff --git a/app/controllers/reviews_controller.rb b/app/controllers/reviews_controller.rb index 1f7c8173..ca35a96e 100644 --- a/app/controllers/reviews_controller.rb +++ b/app/controllers/reviews_controller.rb @@ -170,6 +170,7 @@ def review_params :experience_with_topic, :year, :term, - :grade) + :grade, + :teacher) end end diff --git a/app/models/review.rb b/app/models/review.rb index 6cc36839..5275a05f 100644 --- a/app/models/review.rb +++ b/app/models/review.rb @@ -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 '), @@ -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_/ @@ -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 @@ -149,6 +153,7 @@ def display_grade # grade :integer # notes :string # rating :integer +# teacher :string # term :integer # work_required :integer # year :integer diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e690965c..a20fb8c8 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,7 +7,7 @@ <%= csrf_meta_tags %> <%= csp_meta_tag %> - + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> diff --git a/app/views/reviews/_form.html.erb b/app/views/reviews/_form.html.erb index 9920f4fb..26e25001 100644 --- a/app/views/reviews/_form.html.erb +++ b/app/views/reviews/_form.html.erb @@ -60,6 +60,12 @@ <%= form.number_field :grade, in: 0..100, class: "form-control" %> (between 0 and 100) + +
+ <%= form.label :teacher %> + <%= form.text_field :teacher, class: "form-control" %> + (full name of teacher for the class) +
<%= form.submit 'Submit', class: 'btn btn-primary' %> diff --git a/app/views/reviews/_list.html.erb b/app/views/reviews/_list.html.erb index 5126fde7..71cdcc14 100644 --- a/app/views/reviews/_list.html.erb +++ b/app/views/reviews/_list.html.erb @@ -27,6 +27,10 @@ <%= filterrific_sorting_link(@filterrific, :course) %> + <%= filterrific_sorting_link(@filterrific, :teacher) %> + <%= filterrific_sorting_link(@filterrific, :user) %> @@ -73,6 +77,7 @@ <%= link_to review.course.department.school.name, school_path(id: review.course.department.school.id) %> <%= link_to review.course.department.name, school_department_path(school_id: review.course.department.school.id, id: review.course.department.id) %> <%= 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) %> + <%= review.teacher %>
<%= review.user.uuid %>
<%= 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 %>
<%= review.rating %> diff --git a/app/views/reviews/show.html.erb b/app/views/reviews/show.html.erb index cdf0966a..0367caba 100644 --- a/app/views/reviews/show.html.erb +++ b/app/views/reviews/show.html.erb @@ -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) %>

+

+ Teacher: + <%= @review.teacher %> +

+

User: <%= @review.user.uuid %> diff --git a/db/migrate/20190728135222_add_prof_to_review.rb b/db/migrate/20190728135222_add_prof_to_review.rb new file mode 100644 index 00000000..39f22730 --- /dev/null +++ b/db/migrate/20190728135222_add_prof_to_review.rb @@ -0,0 +1,5 @@ +class AddProfToReview < ActiveRecord::Migration[5.2] + def change + add_column :reviews, :teacher, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index b1702e87..d0a9925f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -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 diff --git a/erd.pdf b/erd.pdf index 1e999529..c70336af 100644 Binary files a/erd.pdf and b/erd.pdf differ diff --git a/spec/controllers/reviews_controller_spec.rb b/spec/controllers/reviews_controller_spec.rb index af1ba380..c5e96fc5 100644 --- a/spec/controllers/reviews_controller_spec.rb +++ b/spec/controllers/reviews_controller_spec.rb @@ -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 @@ -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 diff --git a/spec/factories/reviews.rb b/spec/factories/reviews.rb index 4945f672..20b69230 100644 --- a/spec/factories/reviews.rb +++ b/spec/factories/reviews.rb @@ -12,6 +12,7 @@ year { rand(2000..2019) } term { rand(4) } grade { rand(100) } + teacher { Faker::Name.name } end end @@ -25,6 +26,7 @@ # grade :integer # notes :string # rating :integer +# teacher :string # term :integer # work_required :integer # year :integer diff --git a/spec/models/review_spec.rb b/spec/models/review_spec.rb index a4ef952a..5da67035 100644 --- a/spec/models/review_spec.rb +++ b/spec/models/review_spec.rb @@ -44,7 +44,8 @@ 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, @@ -52,14 +53,16 @@ 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 @@ -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 @@ -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 @@ -228,6 +234,7 @@ # grade :integer # notes :string # rating :integer +# teacher :string # term :integer # work_required :integer # year :integer