Skip to content

Commit

Permalink
Merge pull request #352 from commercekitchen/course_title_truncation
Browse files Browse the repository at this point in the history
Course title truncation
  • Loading branch information
tmichaelreis authored Jan 13, 2020
2 parents a95cdf0 + 6620d26 commit ce6fe7c
Show file tree
Hide file tree
Showing 24 changed files with 146 additions and 212 deletions.
7 changes: 0 additions & 7 deletions app/controllers/concerns/user_courses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ def authorized_courses
courses
end

def load_category_courses
@category_ids = current_organization.categories.enabled.map(&:id)
@disabled_category_ids = current_organization.categories.disabled.map(&:id)
@disabled_category_courses = @courses.where(category_id: @disabled_category_ids)
@uncategorized_courses = @courses.where(category_id: nil) + @disabled_category_courses
end

def current_language_id
english_id = Language.find_by(name: 'English').id || 1
spanish_id = Language.find_by(name: 'Spanish').id || 2
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ def index
@courses = @courses.merge(published_results)
end

load_category_courses

respond_to do |format|
format.html { render :index }
format.json { render json: @courses }
Expand Down
1 change: 0 additions & 1 deletion app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class HomeController < ApplicationController

def index
@courses = authorized_courses
load_category_courses
end

def language_toggle
Expand Down
6 changes: 1 addition & 5 deletions app/controllers/my_courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class MyCoursesController < ApplicationController
before_action :authenticate_user!
include UserCourses

def index
tracked_course_ids = current_user.course_progresses.tracked.collect(&:course_id)
Expand All @@ -14,11 +15,6 @@ def index
@courses = params[:search].blank? ? Course.where(id: tracked_course_ids) : @results
@skip_quiz = current_user.profile.opt_out_of_recommendations

@category_ids = current_organization.categories.enabled.map(&:id)
@disabled_category_ids = current_organization.categories.disabled.map(&:id)
@disabled_category_courses = @courses.where(category_id: @disabled_category_ids)
@uncategorized_courses = @courses.where(category_id: nil) + @disabled_category_courses

respond_to do |format|
format.html { render :index }
format.json { render json: @courses }
Expand Down
14 changes: 14 additions & 0 deletions app/helpers/courses_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,18 @@ def percent_complete_without_user(course, _lesson_id)
percent = 100 if percent > 100
percent.round
end

def courses_completed
user_signed_in? ? current_user.completed_course_ids : []
end

def categorized_courses(courses)
courses.group_by do |course|
if course.category&.enabled?
course.category.name
else
'Uncategorized'
end
end
end
end
2 changes: 1 addition & 1 deletion app/views/courses/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= render "shared/course_intro_text" %>

<% if @courses.count > 0 %>
<%= render partial: "shared/courses/listing", locals: { courses_completed: [] } %>
<%= render "shared/courses/listing" %>
<% else %>
<p>No courses match your search. <%= link_to "View all courses", courses_path %></p>
<% end %>
2 changes: 1 addition & 1 deletion app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<%= render "shared/course_intro_text" %>
<%= render partial: "shared/courses/listing", locals: { courses_completed: [] } %>
<%= render "shared/courses/listing" %>
2 changes: 1 addition & 1 deletion app/views/my_courses/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<% end %>
</p>

<%= render partial: "shared/courses/listing" %>
<%= render "shared/courses/listing" %>

<% if @results && @results.blank? %>
<p>No courses match your search. <%= link_to "View all your courses", my_courses_path %></p>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_search_box.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="search-box">
<%= label_tag search_param, "Search", class: "screen-reader-text" %>
<%= search_field_tag search_param, params[search_param], placeholder: placeholder_text, class: 'search-input' %>
<%= button_tag :submit, class: 'icon-button', 'aria-label' => 'search' do %>
<%= button_tag :submit, class: 'icon-button', id: 'submit-search', 'aria-label' => 'search' do %>
<i class="icon-search grey" id="search-icon"></i>
<% end %>
</div>
Expand Down
12 changes: 12 additions & 0 deletions app/views/shared/courses/_course_widget.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<a class="course-widget<% if courses_completed.include?(course.id) %> completed<% end %>" href="<%= course_path(course) %>" data-cpl-ga-event="on" data-cpl-ga-value="user-open-course">
<header>
<h3 class='course-title'><%= course.title %></h3>
</header>
<div class="description">
<p><%= course.summary %></p>
<div class="percent-complete"><%= percent_complete(course) %></div>
<div class="duration">
<i class="icon-clock grey"></i><%= course.duration %>
</div>
</div>
</a>
49 changes: 4 additions & 45 deletions app/views/shared/courses/_listing.html.erb
Original file line number Diff line number Diff line change
@@ -1,49 +1,8 @@
<% if user_signed_in? %>
<% courses_completed = current_user.completed_course_ids %>
<% else %>
<% courses_completed = [] %>
<% end %>

<% (@category_ids || []).each do |category_id| %>
<% unless @courses.with_category(category_id).blank? %>
<h3><%= Category.find_by_id(category_id).name %></h3>
<% end %>
<div class="container">
<% @courses.with_category(category_id).each do |c| %>
<a class="course-widget<% if courses_completed.include?(c.id) %> completed<% end %>"
href="<%= course_path(c) %>" data-cpl-ga-event="on" data-cpl-ga-value="user-open-course">
<header>
<h3 class='course-title'><%= c.title %></h3>
</header>
<div class="description">
<p><%= c.summary %></p>
<div class="percent-complete"><%= percent_complete(c) %></div>
<div class="duration">
<i class="icon-clock grey"></i><%= c.duration %>
</div>
</div>
</a>
<% end %>
</div>
<% end %>

<% if @uncategorized_courses.present? %>
<h3>Uncategorized</h3>
<% categorized_courses(@courses).each do |category_name, courses| %>
<h3><%= category_name %></h3>
<div class="container">
<% @uncategorized_courses.each do |c| %>
<a class="course-widget<% if courses_completed.include?(c.id) %> completed<% end %>"
href="<%= course_path(c) %>" data-cpl-ga-event="on" data-cpl-ga-value="user-open-course">
<header>
<h3><%= c.title %></h3>
</header>
<div class="description">
<p><%= c.summary %></p>
<div class="percent-complete"><%= percent_complete(c) %></div>
<div class="duration">
<i class="icon-clock grey"></i><%= c.duration %>
</div>
</div>
</a>
<% courses.each do |course| %>
<%= render partial: 'shared/courses/course_widget', locals: { course: course } %>
<% end %>
</div>
<% end %>
Expand Down
15 changes: 0 additions & 15 deletions spec/controllers/courses_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,6 @@
get :index, format: :json
expect(response).to have_http_status(:success)
end

it 'assigns categories' do
get :index
expect(assigns(:category_ids)).to eq([@category1.id])
end

it 'assigns uncategorized courses' do
get :index
expect(assigns(:uncategorized_courses)).to include(@course2, @course3, @disabled_category_course)
end

it 'has correct number of uncategorized courses' do
get :index
expect(assigns(:uncategorized_courses).count).to eq(3)
end
end

describe 'GET #show' do
Expand Down
16 changes: 0 additions & 16 deletions spec/controllers/home_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,6 @@
it 'responds successfully' do
expect(response).to have_http_status(:success)
end

it 'assigns enabled category ids' do
expect(assigns(:category_ids)).to include(category1.id, category2.id)
end

it 'only assigns enabled category ids' do
expect(assigns(:category_ids).length).to eq(2)
end

it 'assigns uncategorized and disabled category courses to uncategorized' do
expect(assigns(:uncategorized_courses)).to include(disabled_category_course, uncategorized_course)
end

it 'assigns correct number of uncategorized courses' do
expect(assigns(:uncategorized_courses).count).to eq(2)
end
end

describe 'GET #home_language_toggle' do
Expand Down
11 changes: 0 additions & 11 deletions spec/controllers/my_courses_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,7 @@
get :index, params: { search: 'java' }
expect(assigns(:courses)).to eq([course1])
end

it 'assigns categories' do
get :index
expect(assigns(:category_ids)).to eq([category.id])
end

it 'assigns uncategorized courses including courses with a disabled category' do
get :index
expect(assigns(:uncategorized_courses)).to include(course3, course4)
end
end

end

context 'non-authenticated user' do
Expand Down
8 changes: 0 additions & 8 deletions spec/factories/course_progresses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,4 @@
user
course
end

factory(:course_progress_with_completed_lessons) do
after(:create) do |course_progress|
create(:completed_lesson, course_progress: course_progress)
create(:completed_lesson, course_progress: course_progress)
create(:completed_lesson, course_progress: course_progress)
end
end
end
2 changes: 1 addition & 1 deletion spec/features/admin/admin_logs_in_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
end

context 'with valid profile' do
scenario 'is sent to admin home page' do
scenario 'is sent to admin dashboard page' do
log_in_with @user.email, @user.password
expect(current_path).to eq(admin_dashboard_index_path)
end
Expand Down
6 changes: 6 additions & 0 deletions spec/features/admin/admin_walkthrough_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
click_link 'Account'
expect(current_path).to eq(profile_path)

within('.main-logo') do
find('a').click
end
expect(current_path).to eq(root_path)
expect(page).to have_content('Edit a course by clicking on a course below,')

click_link 'Sign Out'
expect(current_path).to eq(root_path)
expect(page).to have_content('Signed out successfully.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
create(:default_organization)
end

scenario 'visits root path' do
visit root_path
expect(page).to have_content('Choose a course below to start learning or search courses.')
end

scenario 'can visit the customization page' do
page = create(:cms_page, title: 'Pricing & Features')
visit cms_page_path(page)
Expand Down
5 changes: 0 additions & 5 deletions spec/features/user/account_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@
expect(page).to have_content 'Profile was successfully updated.'
expect(page).to have_content 'Preferred Language'
end

scenario 'can view completed courses' do
# visit courses_completed_path
end

end

context 'belongs to program subdomain' do
Expand Down
28 changes: 28 additions & 0 deletions spec/features/user/search_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require 'feature_helper'

feature 'User searches for courses' do
let(:org) { FactoryBot.create(:organization) }
let(:user) { FactoryBot.create(:user, organization: org) }
let!(:course) { FactoryBot.create(:course, organization: org) }

before do
switch_to_subdomain(org.subdomain)
login_as(user)
visit root_path
end

scenario 'no courses found' do
fill_in 'Search', with: 'foobar'
click_on('submit-search')
expect(page).to have_content('No courses match your search.')
expect(page).to have_link('View all courses', href: courses_path)
end

scenario 'course found' do
fill_in 'Search', with: course.title
click_on('submit-search')
expect(page).to have_content(course.summary)
end
end
6 changes: 6 additions & 0 deletions spec/features/user/user_walkthrough_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
expect(current_path).to eq(my_courses_path)
expect(page).to_not have_link('Profile')

within('.main-logo') do
find('a').click
end
expect(current_path).to eq(root_path)
expect(page).to have_content('Choose a course below to start learning')

click_link 'Sign Out'
expect(current_path).to eq(root_path)
expect(page).to have_content('Signed out successfully.')
Expand Down
Loading

0 comments on commit ce6fe7c

Please sign in to comment.