Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

course edit page based on wireframe #9

Merged
merged 13 commits into from
Sep 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions COMMENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# on view specs
View specs are good for verifying page-elements and structure. However if we're doing page_objects as well we might as well use those rather than duplicating the effort.
After all we put most of the structure into the page-object. If we had a way to specify what elements are always there (default in site-prism is ALL) we could easily make 90% of our view
spec a simple verification of the page object `@page.all_there?`. This of course doesn't cover logic in the view but that's trivial with the page-object too.
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ group :development, :test do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'

gem 'rspec-rails', '~> 3.0'

gem 'factory_girl_rails' # :development to help out in rails generators
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ GEM
addressable (>= 2.3.3, < 3.0)
capybara (>= 2.1, < 3.0)
slop (3.6.0)
spring (1.3.6)
sprockets (3.3.3)
rack (~> 1.0)
sprockets-rails (2.3.2)
Expand Down Expand Up @@ -294,7 +293,6 @@ DEPENDENCIES
selenium-webdriver
shoulda-matchers
site_prism
spring
sqlite3
turbolinks
uglifier (>= 1.3.0)
Expand Down
15 changes: 8 additions & 7 deletions Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# * zeus: 'zeus rspec' (requires the server to be started separately)
# * 'just' rspec: 'rspec'

guard :rspec, cmd: "bundle exec rspec" do
guard :rspec, cmd: "zeus rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)

Expand Down Expand Up @@ -72,7 +72,8 @@ guard :rspec, cmd: "bundle exec rspec" do
end
end

guard 'zeus' do
# see issue: https://github.com/guard/guard-zeus/issues/30
guard 'zeus', run_all: false, rspec: false do
require 'ostruct'

rspec = OpenStruct.new
Expand All @@ -86,11 +87,11 @@ guard 'zeus' do
# Ruby apps
ruby = OpenStruct.new
ruby.lib_files = /^(lib\/.+)\.rb$/

watch(rspec.spec_files)
watch(rspec.spec_helper) { rspec.spec_dir }
watch(ruby.lib_files) { |m| rspec.spec.call(m[1]) }

# see issue: https://github.com/guard/guard-zeus/issues/30
# watch(rspec.spec_files)
# watch(rspec.spec_helper) { rspec.spec_dir }
# watch(ruby.lib_files) { |m| rspec.spec.call(m[1]) }
# Rails example
rails = OpenStruct.new
rails.app_files = /^app\/(.+)\.rb$/
Expand Down
8 changes: 5 additions & 3 deletions README.rdoc → README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
== README
# README

Helps teaching staff determine the best times for office hours by allowing students to input the times they cannot (or can) come to office hours.
Teaching staff can then elect to hold their office hours at times when more students are available. This maximizes the number of students able to get help and decreases the time wasted in office hours when no students attend.

== OTHER
# OTHER

This repo is also a repository for experiments with FullCalendar (http://fullcalendar.io/) and time conversion issues in Rails and moment.js.
In addition it contains an example of using site-prism and capybara with fullcalendar.

== LICENSE
See also [comments](COMMENTS.md) for interesting discoveries made throughout the project.

# LICENSE
MIT
Binary file added app/assets/images/calendar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/assets/stylesheets/courses.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Place all the styles related to the courses controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

img.mini-cal {
height: 100px;
margin-left: 20px;
}
28 changes: 28 additions & 0 deletions app/helpers/courses_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@ def as_a_student(courses)
as_a('student', courses)
end


#take a course and return something like:
# { students: [ { email: '[email protected]', created_at ...} , ],
# educators: [ { email... } ],
# others: []
# }
def user_courses_by_type(course)
students = []
educators = []
others = []
course.course_participants.each do |cp|
case cp.role.role_name
when 'student'
students << cp.user
when 'educator'
educators << cp.user
else
others << cp.user
end
end
{ students: students,
educators: educators,
others: others
}
end

private

def as_a(role_name, courses)
Expand All @@ -18,3 +44,5 @@ def as_a(role_name, courses)
end
end
end


20 changes: 20 additions & 0 deletions app/views/courses/_participants_list.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<% users = user_courses_by_type(@course).delete_if { |k,v| v.blank? } %>
<% users.keys.each do |type| %>
<h3><%= type %></h3>
<table class='type-<%=type%>'>
<thead>
<tr>
<th>email</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% users[type.to_sym].each do |participant| %>
<tr>
<td><%= participant[:email] %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

17 changes: 17 additions & 0 deletions app/views/courses/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
<h1>Editing Course</h1>

<h2>Course information</h2>
<%= render 'form' %>
<div id='scheduling'>
<h2>Scheduling</h2>
<h3>Optimal meeting times (calculated)</h3>
<%=image_tag('calendar.png', alt: 'optimal meeting times', class: 'mini-cal') %>
<h3>Edit my available times</h3>
<%= link_to course_calendar_path(@course) do %>
<%=image_tag('calendar.png', alt: 'optimal meeting times', class: 'mini-cal') %>
<% end %>
</div>

<div id='participants'>
<h2>Course Participants</h2>
<%= render 'participants_list' %>
</div>

<%= link_to 'Show', @course %> |
<%= link_to 'Back', courses_path %>


4 changes: 0 additions & 4 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
4 changes: 0 additions & 4 deletions bin/rake
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
require_relative '../config/boot'
require 'rake'
Rake.application.run
15 changes: 0 additions & 15 deletions bin/spring

This file was deleted.

5 changes: 5 additions & 0 deletions spec/factories/course_participants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
factory :course_participant do
role
course
user

trait :student do
association :role, factory: :student_role
Expand All @@ -11,6 +12,10 @@
association :role, factory: :educator_role
end

trait :with_new_user do
association :user, factory: :user
end

factory :student_participant, traits: [:student]
factory :educator_participant, traits: [:educator]
end
Expand Down
34 changes: 34 additions & 0 deletions spec/factories/courses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,39 @@
cp.save!
end
end

# huge factory that generates an entire stack of courses with users and roles
# please only use when really needed and in integration tests
factory :course_with_many_users do
transient { educators 2 }
transient { students 3 }

after(:create) do |course, evaluator|
educator_users = create_list(:educator_participant,
evaluator.educators.to_i,
:with_new_user,
course: course
)
student_users = create_list(:student_participant,
evaluator.students.to_i,
:with_new_user,
course: course
)
end
end
end
# build up a full deep hash from courses to users and roles
factory :course_with_many_users_hash, class: Hash do
transient { title 'Rocket Science' }
after(:build) do |course, evaluator|
participants = FactoryGirl.attributes_for_list(:student_role, 7)
participants += FactoryGirl.attributes_for_list(:educator_role, 2)
users = attributes_for_list(:user,9)
participants.each_with_index do |part, index|
part[:user] = users[index]
end
course[:course_participants] = participants
course[:title] = evaluator.title
end
end
end
49 changes: 49 additions & 0 deletions spec/features/courses_editing_feature_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'rails_helper'

RSpec.feature "Editing courses",
%q{
As a teacher or student,
I want to edit the courses I'm involved in,
},
:js do


given!(:course) { FactoryGirl.create(:course_with_many_users, students: 3) } # a huge factory
given(:teacher) { course.course_participants.where( role: Role.educator ).first.user }
given(:one_student) { course.course_participants.where(role: Role.student)[2].user }

before do
UsersSignInPage.sign_in_user(teacher.email)
@p = CoursesIndexPage.new
@p.load
@p.teaching_courses.first.edit_link.click
@p = CoursesEditPage.new
end

it 'displays the page elements' do # verify the page-object ?
expect(@p).to be_displayed
expect(@p).to be_all_there
end

scenario "changing the course name" do
@p.title_field.set 'Saving Christmas'
@p.update_button.click
@p = CoursesIndexPage.new
# below is not implemented
#expect(@p).to be_displayed
#expect(@p.teaching_courses_table).to have_content 'Saving Christmas'
# instead we'll just check this for now:
expect(page).to have_content 'Saving Christmas'
end

scenario 'shows us the course participants broken into educators and students' do
expect(@p.students.count).to eq 3
expect(@p.educators.count).to eq 2
end

scenario 'can proceed to view my calendar' do
@p.edit_calendar_link.click
@p = CourseParticipantsPage.new
expect(@p).to be_displayed
end
end
22 changes: 22 additions & 0 deletions spec/helpers/courses_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,26 @@
expect(res.count).to eq 3
end
end

describe '#user_courses_by_role' do
let(:student) { FactoryGirl.create(:user) }
let(:teacher) { FactoryGirl.create(:user) }
let(:course) { FactoryGirl.create(:course_for_user, user: student) }
before { FactoryGirl.create(:educator_participant, course: course, user: teacher) }
subject(:result) { helper.user_courses_by_type(course) }
it 'returns a hash with keys :students, :teachers, :other' do
expect(result).to be_a Hash
expect(result.keys) =~ [ :students, :teachers, :other ]
end
it 'has an array of students in the students hash' do
expect(result[:students]).to be_an Array
expect(result[:students].first.email).to eq student.email
end

it 'has an array of educators under the educators keys' do
expect(result[:educators]).to be_an Array
expect(result[:educators].first.email).to eq teacher.email
end

end
end
3 changes: 3 additions & 0 deletions spec/page_objects/pages/course_participants_page.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class CourseParticipantsPage < SitePrism::Page
# set_url 'course_participants/{:id}/'
set_url '/courses/{:course_id}/calendar'
set_url_matcher /courses.*\/calendar/

section :calendar, WeekCalendarSection, '#calendar'

element :save_button, 'input[name="commit"]'
Expand All @@ -17,3 +19,4 @@ def self.navigate_here
page.navigate_here
end
end

14 changes: 14 additions & 0 deletions spec/page_objects/pages/courses_edit_page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CoursesEditPage < SitePrism::Page
set_url '/courses/{course_id}/edit'
set_url_matcher /courses.*\/edit/
element :title_field, 'input#course_title'
element :update_button, 'input[name="commit"]'

element :edit_calendar_link, 'div#scheduling a'
element :educators_table, 'table.type-educators'
elements :educators, 'table.type-educators tbody tr'

element :students_table, 'table.type-students'
elements :students, 'table.type-students tbody tr'

end
4 changes: 4 additions & 0 deletions spec/support/capybara_string.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def capybara(some_str=nil)
some_str = rendered if some_str.nil?
Capybara.string(some_str)
end
Loading