fix more issues with recent changes

This commit is contained in:
Seth Call 2016-05-20 14:31:05 -05:00
parent 7737f0977e
commit 7a4be8292f
7 changed files with 94 additions and 32 deletions

View File

@ -490,19 +490,34 @@ module JamRuby
query = query.order('music_sessions.scheduled_start DESC')
if params[:as_teacher].present?
if params[:as_teacher]
if params[:as_teacher] == true || params[:as_teacher] == "true"
if user.teacher && user.teacher.school_id
school_extra = "OR (lesson_bookings.school_id = '#{user.teacher.school_id}')"
else
school_extra = ''
end
query = query.where('lesson_sessions.teacher_id = ?', user.id)
else
if user.school_id
school_extra = "OR (lesson_bookings.school_id = '#{user.school_id}')"
else
school_extra = ''
end
query = query.where('music_sessions.user_id = ?', user.id)
end
else
query = query.where('(lesson_sessions.teacher_id = ? or music_sessions.user_id = ?)', user.id, user.id)
end
if user.school_id
school_extra = "OR (lesson_bookings.school_id = '#{user.school_id}')"
else
school_extra = ''
if user.school_id
school_extra = "OR (lesson_bookings.school_id = '#{user.school_id}')"
else
school_extra = ''
end
query = query.where('(lesson_sessions.teacher_id = ? or music_sessions.user_id = ?)', user.id, user.id)
end
query = query.where('lesson_bookings.card_presumed_ok = true OR (music_sessions.user_id = ?) ' + school_extra, user.id)

View File

@ -98,6 +98,8 @@ FactoryGirl.define do
factory :teacher_user do
after(:create) do |user, evaluator|
teacher = FactoryGirl.create(:teacher, user: user, price_per_lesson_60_cents: 3000, price_per_month_60_cents: 3000)
user.is_a_teacher = true
user.save!
end
end
end

View File

@ -35,6 +35,15 @@ LessonTimerActions = context.LessonTimerActions
has_pricing_specified: {name: 'Pricing', teacher_profile: "pricing"}
}
needsFetching: false
fetchLessons: () ->
if @needsFetching
if @state.user?.id?
@needsFetching = false
rest.getLessonSessions({as_teacher: @viewerTeacher()}).done((response) => @jamClassLoaded(response)).fail((jqXHR) => @failedJamClassLoad(jqXHR))
onAppInit: (@app) ->
@app.bindScreen('jamclass',
{beforeShow: @beforeShow, afterShow: @afterShow, beforeHide: @beforeHide})
@ -57,6 +66,7 @@ LessonTimerActions = context.LessonTimerActions
lesson.times = lessonWithTime.times
componentDidUpdate: () ->
@fetchLessons()
items = @root.find('.jamtable tbody td.actionsColumn .lesson-session-actions-btn')
$.each(items, (i, node) => (
@ -218,7 +228,8 @@ LessonTimerActions = context.LessonTimerActions
afterShow: (e) ->
@checkStripeSuccessReturn()
@setState({updating: true})
rest.getLessonSessions().done((response) => @jamClassLoaded(response)).fail((jqXHR) => @failedJamClassLoad(jqXHR))
@needsFetching = true
@fetchLessons()
checkStripeSuccessReturn: () ->
if $.QueryString['stripe-success']?
@ -287,7 +298,7 @@ LessonTimerActions = context.LessonTimerActions
# if this is a not-confirmed lesson, send them to the view statu screen
if lesson_session.isRequested
window.location.href = '/client#/jamclass/lesson-booking/' + lesson.id
window.location.href = '/client#/jamclass/lesson-booking/' + lesson_session.id
else
@app.layout.showDialog('chat-dialog', {d1: 'lesson_' + lesson_session.id})

View File

@ -113,6 +113,8 @@ FactoryGirl.define do
after(:create) do |user, evaluator|
user.password_confirmation = nil
teacher = FactoryGirl.create(:teacher, user: user, price_per_lesson_60_cents: 3000, price_per_month_60_cents: 3000, lesson_duration_60: true, prices_per_lesson: true, prices_per_month: true)
user.is_a_teacher = true
user.save!
end
end
end

View File

@ -27,8 +27,6 @@ describe "Single Lesson", :js => true, :type => :feature, :capybara_feature => t
teacher_user.teacher.save!
teacher_user.teacher.price_per_lesson_60_cents.should eql 3000
Teacher.index(user, {})[:query].count.should eql 1
end
describe "register via showing interesting in teacher 1st" do
@ -177,8 +175,6 @@ describe "Single Lesson", :js => true, :type => :feature, :capybara_feature => t
analysis["reason"].should eql LessonSessionAnalyser::SUCCESS
lesson_session1.success.should be_true
lesson_session1.billing_attempts.should eql 1
puts lesson_session1.billing_error_reason
puts lesson_session1.billing_error_detail
lesson_session1.billed.should eql true
LessonBooking.hourly_check
@ -332,11 +328,9 @@ describe "Single Lesson", :js => true, :type => :feature, :capybara_feature => t
user.remaining_test_drives.should eql 1
user.sales.count.should eql 1
bookings = LessonBooking.where(teacher_id: lesson_session.teacher.id)
bookings = LessonBooking.where(teacher_id: lesson_session1.teacher.id)
bookings.each do |b|
puts "BOOKING: #{b.inspect}"
end
LessonSession.index(lesson_session1.teacher, {as_teacher:true})[:query].count.should eql 1
# approve by teacher:
teacher_approve(lesson_session1)

View File

@ -1,12 +1,12 @@
require 'spec_helper'
describe "Test Drive", :js => true, :type => :feature, :capybara_feature => true do
describe "JamClassScreen", :js => true, :type => :feature, :capybara_feature => true do
subject { page }
let(:user) { FactoryGirl.create(:user, traditional_band: true,paid_sessions: true, paid_sessions_hourly_rate: 1, paid_sessions_daily_rate:1 ) }
let(:teacher_user) {FactoryGirl.create(:teacher_user, ready_for_session_at: Time.now)}
let(:teacher_user2) {FactoryGirl.create(:teacher_user, ready_for_session_at: Time.now)}
let(:teacher_user) {FactoryGirl.create(:teacher_user, ready_for_session_at: Time.now, first_name: "TeacherUser1")}
let(:teacher_user2) {FactoryGirl.create(:teacher_user, ready_for_session_at: Time.now, first_name: "TeacherUser2")}
it "shows Missed (Both)" do
lesson = testdrive_lesson(user, teacher_user, {miss: true, accept: true})
@ -37,8 +37,8 @@ describe "Test Drive", :js => true, :type => :feature, :capybara_feature => true
find('#jam-class-student-screen td.displayStatusColumn', text: 'Missed (Teacher)')
# also check that clicking messages icon shows chat dialog (instead of view status screen) # VRFS-4089
find('tr[data-lesson-session-id="' + lesson.id + '"] a.unreadColumn').trigger(:click)
find('h1', text: 'respond to lesson request')
find('tr[data-lesson-session-id="' + lesson.id + '"] td.unreadColumn a').trigger(:click)
find('.chat-list-scroller')
end
it "shows Completed" do
@ -57,27 +57,57 @@ describe "Test Drive", :js => true, :type => :feature, :capybara_feature => true
fast_signin(teacher_user, "/client#/jamclass")
find('#jam-class-student-screen td.displayStatusColumn', text: 'Requested')
# open up hover
find('tr[data-lesson-session-id="' + lesson.id + '"] .lesson-session-actions-btn').trigger(:click)
find('li[data-lesson-option="cancel"] a', visible: false, text: 'Decline Request')
sign_out_poltergeist
sleep 4
fast_signin(user, "/client#/jamclass")
lesson.teacher_unread_messages.should be_true
# also check that clicking messages icon shows view status screen (instead of chat dialog) # VRFS-4089
find('tr[data-lesson-session-id="' + lesson.id + '"] a.unreadColumn').trigger(:click)
find('tr[data-lesson-session-id="' + lesson.id + '"] td.unreadColumn a').trigger(:click)
find('h2', text: 'respond to lesson request')
switch_user(user, "/client#/jamclass")
lesson.reload
lesson.student_unread_messages.should be_false
find('#jam-class-student-screen td.displayStatusColumn', text: 'Requested')
# open up hover
find('tr[data-lesson-session-id="' + lesson.id + '"] .lesson-session-actions-btn').trigger(:click)
# should work, doesn't
#find('li[data-lesson-option="cancel"] a', visible: false, text: 'Cancel Request')
find('li[data-lesson-option="cancel"] a', visible: false, text: 'Cancel Request').trigger(:click)
# confirm cancelation -
find('#banner .yes-btn', text: 'YES').trigger(:click)
find('#jam-class-student-screen td.displayStatusColumn', text: 'Canceled (Student)')
switch_user(teacher_user, "/client#/jamclass")
find('#jam-class-student-screen td.displayStatusColumn', text: 'Canceled (Student)')
end
it "Teacher cancelation" do
lesson = testdrive_lesson(user, teacher_user, {accept: false})
fast_signin(teacher_user, "/client#/jamclass")
find('#jam-class-student-screen td.displayStatusColumn', text: 'Requested')
# open up hover
find('tr[data-lesson-session-id="' + lesson.id + '"] .lesson-session-actions-btn').trigger(:click)
find('li[data-lesson-option="cancel"] a', visible: false, text: 'Decline Request').trigger(:click)
# confirm cancelation -
find('#banner .yes-btn', text: 'YES').trigger(:click)
find('#jam-class-student-screen td.displayStatusColumn', text: 'Canceled (Teacher)')
switch_user(user, "/client#/jamclass")
find('#jam-class-student-screen td.displayStatusColumn', text: 'Canceled (Teacher)')
end
end

View File

@ -197,10 +197,18 @@ def sign_out
end
end
def switch_user(user, url)
sign_out_poltergeist(validate:true)
fast_signin(user, url)
end
def sign_out_poltergeist(options = {})
sign_out
open_user_dropdown
click_link 'Sign Out'
should_be_at_logged_out_client if options[:validate]
if options[:validate]
visit "/"
find('#jamclass-link')
end
end
def open_user_dropdown