The Big List of View Specs

I recently received a polite request for view specs to be included in RSpec Rails Examples. I hope to contribute a view spec or two for it, though, as this may not happen for a while, here’s an alternative resource for the Rails community: a list of 250+ view specs gathered from real world apps.

Occasionally mentors have been in short supply during my career. At those times, reading other people’s open source contributions has served well as a substitute teacher. I hope this resource will help newer developers to discover the same. Thank you to everyone whose open source work is shown below.

If you’d like to generate this list of specs, and to browse the source for these and other Rails apps on your computer, install Real World Rails and run bin/rwr view-specs

# File: apps/alaveteli/spec/views/public_body/show.html.erb_spec.rb# -*- encoding : utf-8 -*-requireFile.expand_path(File.join('..','..','..','spec_helper'), __FILE__)
describe "public_body/show"do
before do@pb=mock_model(PublicBody,:name=>'Test Quango',:short_name=>'tq',:url_name=>'testquango',:notes=>'',:tags=>[],:eir_only?=>nil,:info_requests=>[1,2,3,4],# out of sync with Xapian:publication_scheme=>'',:disclosure_log=>'',:calculated_home_page=>'')@pb.stub!(:is_requestable?).and_return(true)@pb.stub!(:special_not_requestable_reason?).and_return(false)@pb.stub!(:has_notes?).and_return(false)@pb.stub!(:has_tag?).and_return(false)@pb.stub!(:tag_string).and_return('')@xap=mock(ActsAsXapian::Search,:matches_estimated=>2)@xap.stub!(:results).and_return([{:model=> mock_event },{:model=> mock_event }])assign(:public_body,@pb)assign(:track_thing,mock_model(TrackThing,:track_type=>'public_body_updates',:public_body=>@pb,:params=>{}))assign(:xapian_requests,@xap)assign(:page,1)assign(:per_page,10)assign(:number_of_visible_requests,4)end
it "should be successful"do
render
controller.response.should be_success
end
it "should show the body's name"do
render
response.should have_selector('h1',:content=>"Test Quango")end
it "should tell total number of requests"do
render
response.should match "4 requests"end
it "should cope with no results"doassign(:number_of_visible_requests,0)
render
response.should have_selector('p',:content=>"Nobody has made any Freedom of Information requests")end
it "should cope with Xapian being down"doassign(:xapian_requests,nil)
render
response.should match "The search index is currently offline"endenddef mock_event
returnmock_model(InfoRequestEvent,:info_request=>mock_model(InfoRequest,:title=>'Title',:url_title=>'title',:display_status=>'waiting_response',:calculate_status=>'waiting_response',:public_body=>@pb,:is_external?=>false,:user=>mock_model(User,:name=>'Test User',:url_name=>'testuser')),:incoming_message=>nil,:is_incoming_message?=>false,:outgoing_message=>nil,:is_outgoing_message?=>false,:comment=>nil,:is_comment?=>false,:event_type=>'sent',:created_at=>Time.now -4.days,:search_text_main=>'')end

# File: apps/alaveteli/spec/views/request/_after_actions.html.erb_spec.rb# -*- encoding : utf-8 -*-requireFile.expand_path(File.join('..','..','..','spec_helper'), __FILE__)
describe 'when displaying actions that can be taken with regard to a request'do
before do@mock_body=mock_model(PublicBody,:name=>'test public body',:url_name=>'test_public_body')@mock_user=mock_model(User,:name=>'test user',:url_name=>'test_user')@mock_request=mock_model(InfoRequest,:title=>'test request',:user=>@mock_user,:user_name=>@mock_user.name,:is_external?=>false,:public_body=>@mock_body,:comments_allowed?=>true,:url_title=>'test_request',:all_can_view?=>true)
assign :info_request,@mock_requestend
describe 'if the request is old and unclassified'do
before do
assign :old_unclassified,trueend
it 'should not display a link for the request owner to update the status of the request'do
render :partial=>'request/after_actions'
response.should have_selector('div#owner_actions') do |div|
div.should_not have_selector('a',:content=>'Update the status of this request')endend
it 'should display a link for anyone to update the status of the request'do
render :partial=>'request/after_actions'
response.should have_selector('div#anyone_actions') do |div|
div.should have_selector('a',:content=>'Update the status of this request')endendend
describe 'if the request is not old and unclassified'do
before do
assign :old_unclassified,falseend
it 'should display a link for the request owner to update the status of the request'do
render :partial=>'request/after_actions'
response.should have_selector('div#owner_actions') do |div|
div.should have_selector('a',:content=>'Update the status of this request')endend
it 'should not display a link for anyone to update the status of the request'do
render :partial=>'request/after_actions'
response.should have_selector('div#anyone_actions') do |div|
div.should_not have_selector('a',:content=>'Update the status of this request')endendend
it 'should display a link for the request owner to request a review'do
render :partial=>'request/after_actions'
response.should have_selector('div#owner_actions') do |div|
div.should have_selector('a',:content=>'Request an internal review')endend
it 'should display the link to download the entire request'do
render :partial=>'request/after_actions'
response.should have_selector('div#anyone_actions') do |div|
div.should have_selector('a',:content=>'Download a zip file of all correspondence')endendend

# File: apps/alaveteli/spec/views/request/_describe_state.html.erb_spec.rb# -*- encoding : utf-8 -*-requireFile.expand_path(File.join('..','..','..','spec_helper'), __FILE__)
describe 'when showing the form for describing the state of a request'dodefexpect_radio_button(value)
do_render
response.should have_selector('input',:type=>'radio',:value=> value)enddefexpect_no_radio_button(value)
do_render
response.should_not have_selector('input',:type=>'radio',:value=> value)enddef do_render
render :partial=>'request/describe_state',:locals=>{:id_suffix=>'1'}end
before do@mock_user=mock_model(User,:name=>'test user',:url_name=>'test_user')@mock_request=mock_model(InfoRequest,:described_state=>'',:user=>@mock_user,:user_name=>@mock_user.name,:is_external?=>false)
assign :info_request,@mock_requestend
describe 'if the user is a regular user (not the request owner)'do
before do
assign :is_owning_user,falseend
describe 'if the request is not old and unclassified'do
it 'should not show the form'do
do_render
response.should_not have_selector('h2',:content=>'What best describes the status of this request now?')end
it 'should give a link to login'do
do_render
response.should have_selector('a',:content=>'sign in')endend
describe 'if the request is old and unclassified'do
before do
assign :old_unclassified,trueend
it 'should not show the form'do
do_render
response.should_not have_selector('h2',:content=>'What best describes the status of this request now?')end
it 'should show the form for someone else to classify the request'do
do_render
response.should have_selector('h2',:content=>'We need your help')end
it 'should not give a link to login'do
do_render
response.should_not have_selector('a',:content=>'sign in')endendend
describe 'if showing the form to the user owning the request'do
before do
assign :is_owning_user,trueend
describe 'when the request is not in internal review'do
before do@mock_request.stub!(:described_state).and_return('waiting response')end
it 'should show a radio button to set the status to "waiting response"'doexpect_radio_button('waiting_response')end
it 'should show a radio button to set the status to "waiting clarification"'doexpect_radio_button('waiting_clarification')end
it 'should not show a radio button to set the status to "internal_review"'doexpect_no_radio_button('internal_review')endend
describe 'when the user has asked to update the status of the request'do
before do
assign :update_status,trueend
it 'should show a radio button to set the status to "internal_review"'doexpect_radio_button('internal_review')end
it 'should show a radio button to set the status to "requires_admin"'doexpect_radio_button('requires_admin')end
it 'should show a radio button to set the status to "user_withdrawn"'doexpect_radio_button('user_withdrawn')endend
describe 'when the request is in internal review'do
before do@mock_request.stub!(:described_state).and_return('internal_review')end
it 'should show a radio button to set the status to "internal review"'doexpect_radio_button('internal_review')end
it 'should show the text "The review has finished and overall:"'do
do_render
response.should have_selector('p',:content=>'The review has finished and overall:')endend
describe 'when request is awaiting a description and the user has not asked to update the status'doend
it 'should show a radio button to set the status to "gone postal"'doexpect_radio_button('gone_postal')end
it 'should show a radio button to set the status to "not held"'doexpect_radio_button('not_held')end
it 'should show a radio button to set the status to "partially successful"'doexpect_radio_button('partially_successful')end
it 'should show a radio button to set the status to "successful"'doexpect_radio_button('successful')end
it 'should show a radio button to set the status to "rejected"'doexpect_radio_button('rejected')end
it 'should show a radio button to set the status to "error_message"'doexpect_radio_button('error_message')end
it 'should not show a radio button to set the status to "requires_admin"'doexpect_no_radio_button('requires_admin')end
it 'should not show a radio button to set the status to "user_withdrawn"'doexpect_no_radio_button('user_withdrawn')endendend

# File: apps/alaveteli/spec/views/request/show.html.erb_spec.rb# -*- encoding : utf-8 -*-requireFile.expand_path(File.join('..','..','..','spec_helper'), __FILE__)
describe 'request/show'do
before do@mock_body=mock_model(PublicBody,:name=>'test body',:url_name=>'test_body',:is_school?=>false)@mock_user=mock_model(User,:name=>'test user',:url_name=>'test_user',:profile_photo=>nil)@mock_request=mock_model(InfoRequest,:title=>'test request',:awaiting_description=>false,:law_used_with_a=>'A Freedom of Information request',:law_used_full=>'Freedom of Information',:public_body=>@mock_body,:user=>@mock_user,:user_name=>@mock_user.name,:is_external?=>false,:calculate_status=>'waiting_response',:date_response_required_by=>Date.today,:prominence=>'normal',:comments_allowed?=>true,:all_can_view?=>true,:url_title=>'test_request')enddef request_page
assign :info_request,@mock_request
assign :info_request_events,[]
assign :status,@mock_request.calculate_status
render
end
describe 'when a status update has been requested'do
before do
assign :update_status,trueend
it 'should show the first form for describing the state of the request'do
request_page
response.should have_selector("div.describe_state_form#describe_state_form_1")endend
describe 'when it is awaiting a description'do
before do@mock_request.stub!(:awaiting_description).and_return(true)end
it 'should show the first form for describing the state of the request'do
request_page
response.should have_selector("div.describe_state_form#describe_state_form_1")end
it 'should show the second form for describing the state of the request'do
request_page
response.should have_selector("div.describe_state_form#describe_state_form_2")endend
describe 'when the user is the request owner'do
before do
assign :is_owning_user,trueend
describe 'when the request status is "waiting clarification"'do
before do@mock_request.stub!(:calculate_status).and_return('waiting_clarification')end
describe 'when there is a last response'do
before do@mock_response=mock_model(IncomingMessage)@mock_request.stub!(:get_last_public_response).and_return(@mock_response)end
it 'should show a link to follow up the last response with clarification'do
request_page
expected_url = "/en/request/#{@mock_request.id}/response/#{@mock_response.id}#followup"
response.should have_selector("a",:href=> expected_url,:content=>'send a follow up message')endend
describe 'when there is no last response'do
before do@mock_request.stub!(:get_last_public_response).and_return(nil)end
it 'should show a link to follow up the request without reference to a specific response'do
request_page
expected_url = "/en/request/#{@mock_request.id}/response#followup"
response.should have_selector("a",:href=> expected_url,:content=>'send a follow up message')endendendendend

# File: apps/canvas-lms/spec/views/account_authorization_configs/index.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "account_authorization_configs/index"dolet(:account){Account.default }
before do
assigns[:context]= assigns[:account]= account
assigns[:current_user]= user_model
assigns[:saml_identifiers]=[]
assigns[:saml_authn_contexts]=[]
assigns[:saml_login_attributes]={}end
it "should list the auth ips"doSetting.set('account_authorization_config_ip_addresses',"192.168.0.1,192.168.0.2")
presenter =AccountAuthorizationConfigsPresenter.new(account)
account.authentication_providers =[
presenter.new_config(auth_type:'saml'),
presenter.new_config(auth_type:'saml')]
assigns[:presenter]= presenter
render 'account_authorization_configs/index'expect(response.body).to match("192.168.0.1\n192.168.0.2")end
it "should display the last_timeout_failure"do
timed_out_aac = account.account_authorization_configs.create!(auth_type:'ldap')
account.authentication_providers =[
timed_out_aac,
account.account_authorization_configs.create!(auth_type:'ldap')]
timed_out_aac.last_timeout_failure =1.minute.ago
timed_out_aac.save!
presenter =AccountAuthorizationConfigsPresenter.new(account)expect(presenter.configs).to include(timed_out_aac)
assigns[:presenter]= presenter
render 'account_authorization_configs/index'
doc =Nokogiri::HTML(response.body)expect(doc.css('.last_timeout_failure').length).to eq 1end
it "should display more than 2 LDAP configs"do
account.authentication_providers.each(&:destroy)4.times do
account.authentication_providers.create!(auth_type:'ldap')end
assigns[:presenter]=AccountAuthorizationConfigsPresenter.new(account)
render 'account_authorization_configs/index'
doc =Nokogiri::HTML(response.body)expect(doc.css('input[value=ldap]').length).to eq(5)# 4 + 1 hidden for newendend

# File: apps/canvas-lms/spec/views/accounts/_add_course_or_user.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "accounts/_add_course_or_user.html.erb"do
describe "sis_source_id with sis_batches"do
before do@account=Account.default
@account.allow_sis_import =true@account.save
assigns[:account]=@account
assigns[:root_account]=@accountend
it "should show to sis admin"do
admin = account_admin_user
view_context(@account, admin)
assigns[:current_user]= admin
render
expect(response).to have_tag("input#pseudonym_sis_user_id")end
it "should not show to non-sis admin"do
admin =account_admin_user_with_role_changes(:role_changes=>{'manage_sis'=>false})view_context(@account, admin)
assigns[:current_user]= admin
render
expect(response).not_to have_tag("input#pseudonym_sis_source_id")endend
describe "sis_source_id without sis_batches"do
before do@account=Account.default
@account.allow_sis_import =false@account.save
assigns[:account]=@account
assigns[:root_account]=@accountend
it "should not show to sis admin, because there are no sis batches"do
admin = account_admin_user
view_context(@account, admin)
assigns[:current_user]= admin
render
expect(response).not_to have_tag("input#pseudonym_sis_user_id")end
it "should not show to non-sis admin"do
admin =account_admin_user_with_role_changes(:role_changes=>{'manage_sis'=>false})view_context(@account, admin)
assigns[:current_user]= admin
render
expect(response).not_to have_tag("input#pseudonym_sis_source_id")endendend

# File: apps/canvas-lms/spec/views/accounts/_sis_batch_counts.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "accounts/_sis_batch_counts.html.erb"do
it "should render sis count data"do
data ={:counts=>{:xlists=>2,:enrollments=>3,:courses=>5,:users=>6,:terms=>6,:group_memberships=>7,:groups=>8,:sections=>9,:accounts=>10}}
report =mock()
report.expects(:data).returns(data)
render :partial=>'accounts/sis_batch_counts',:object=> report
map ={:xlists=>"Crosslists",:group_memberships=>"Group Enrollments"}
data[:counts].each_pair do|type, count|
name = map[type]|| type.to_s.capitalize
expect(response.body).to match /#{name}: #{count}/endendend

# File: apps/canvas-lms/spec/views/accounts/settings.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "accounts/settings.html.erb"do
before do
assigns[:account_roles]=[]
assigns[:course_roles]=[]end
describe "sis_source_id edit box"do
before do@account=Account.default.sub_accounts.create!@account.sis_source_id ="so_special_sis_id"@account.save!
assigns[:context]=@account
assigns[:account]=@account
assigns[:account_users]=[]
assigns[:root_account]=@account
assigns[:associated_courses_count]=0
assigns[:announcements]=[]end
it "should show to sis admin"do
admin = account_admin_user
view_context(@account, admin)
assigns[:current_user]= admin
render
expect(response).to have_tag("input#account_sis_source_id")end
it "should not show to non-sis admin"do
admin =account_admin_user_with_role_changes(:role_changes=>{'manage_sis'=>false})view_context(@account, admin)
assigns[:current_user]= admin
render
expect(response).to have_tag("span.sis_source_id",@account.sis_source_id)expect(response).not_to have_tag("input#account_sis_source_id")endend
describe "open registration"do
before do@account=Account.default
assigns[:account]=@account
assigns[:account_users]=[]
assigns[:root_account]=@account
assigns[:associated_courses_count]=0
assigns[:announcements]=[]
admin = account_admin_user
view_context(@account, admin)end
it "should show by default"do
render
expect(response).to have_tag("input#account_settings_open_registration")expect(response).not_to have_tag("div#open_registration_delegated_warning_dialog")end
it "should show warning dialog when a delegated auth config is around"do@account.authentication_providers.create!(:auth_type=>'cas')
render
expect(response).to have_tag("input#account_settings_open_registration")expect(response).to have_tag("div#open_registration_delegated_warning_dialog")endend
describe "managed by site admins"do
before do@account=Account.default
assigns[:account]=@account
assigns[:account_users]=[]
assigns[:root_account]=@account
assigns[:associated_courses_count]=0
assigns[:announcements]=[]end
it "should show settings that can only be managed by site admins"do
admin = site_admin_user
view_context(@account, admin)
render
expect(response).to have_tag("input#account_settings_global_includes")expect(response).to have_tag("input#account_settings_show_scheduler")expect(response).to have_tag("input#account_settings_enable_profiles")end
it "it should not show settings to regular admin user"do
admin = account_admin_user
view_context(@account, admin)
render
expect(response).not_to have_tag("input#account_settings_global_includes")expect(response).not_to have_tag("input#account_settings_show_scheduler")expect(response).not_to have_tag("input#account_settings_enable_profiles")endend
describe "quotas"do
before do@account=Account.default
assigns[:account]=@account
assigns[:account_users]=[]
assigns[:root_account]=@account
assigns[:associated_courses_count]=0
assigns[:announcements]=[]end
context "with :manage_storage_quotas"do
before do
admin = account_admin_user
view_context(@account, admin)
assigns[:current_user]= admin
end
it "should show quota options"do
render
expect(@controller.js_env.include?(:ACCOUNT)).to be_truthy
expect(response).to have_tag '#tab-quotas-link'expect(response).to have_tag '#tab-quotas'endend
context "without :manage_storage_quotas"do
before do
admin =account_admin_user_with_role_changes(:account=>@account,:role_changes=>{'manage_storage_quotas'=>false})view_context(@account, admin)
assigns[:current_user]= admin
end
it "should not show quota options"do
render
expect(@controller.js_env.include?(:ACCOUNT)).to be_falsey
expect(response).not_to have_tag '#tab-quotas-link'expect(response).not_to have_tag '#tab-quotas'endendend
context "admins"do
it "should not show add admin button if don't have permission to any roles"do
role =custom_account_role('CustomAdmin',:account=>Account.site_admin)account_admin_user_with_role_changes(:account=>Account.site_admin,:role=> role,:role_changes=>{manage_account_memberships:true})view_context(Account.default,@user)
assigns[:account]=Account.default
assigns[:announcements]=[]
render
expect(response).not_to have_tag '#enroll_users_form'endendend

# File: apps/canvas-lms/spec/views/announcements/index.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/announcements/index"do
it "should render"do
course_with_teacher
view_context(@course,@user)
assigns[:body_classes]=[]
render 'announcements/index'expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/assignments/_syllabus_content.html.erb_spec.rb## Copyright (C) 2013 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/assignments/_syllabus_content"do
context 'js_env CAN_READ'dodefsetup_and_render_context(type, opts={})case type
when:anonymous
course :active_all=>truewhen:non_enrolled_user
course :active_all=>true
user
when:enrolled_user
course_with_student :active_all=>trueendif opts[:is_public]@course.is_public =true@course.save!enduser_session(@user)if@userview_context(@course,@user)
render '/assignments/_syllabus_content'endbefore(:each)do
course :active_all=>true@course.is_public =true@course.save!end
example 'anonymous user (public course)'do
setup_and_render_context :anonymous,:is_public=>trueexpect(@controller.js_env).to include(:CAN_READ=>true)end
example 'non-enrolled user (public course)'do
setup_and_render_context :non_enrolled_user,:is_public=>trueexpect(@controller.js_env).to include(:CAN_READ=>true)end
example 'enrolled user (non-public course)'do
setup_and_render_context :enrolled_userexpect(@controller.js_env).to include(:CAN_READ=>true)endendend

# File: apps/canvas-lms/spec/views/assignments/redirect_page.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/assignments/redirect_page"do
it "should render"do
course_with_student
view_context(@course,@user)
a =@course.assignments.create(:title=>"some assignment")
s = a.submit_homework(@user)
assigns[:assignment]= a
assigns[:submission]= s
render 'assignments/redirect_page'expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/assignments/show.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/assignments/show"do
it "should render"docourse_with_teacher(active_all:true)view_context(@course,@user)
g =@course.assignment_groups.create!(:name=>"some group")
a =@course.assignments.create!(:title=>"some assignment")
a.assignment_group_id = g.id
a.save!
assigns[:assignment]= a
assigns[:assignment_groups]=[g]
assigns[:current_user_rubrics]=[]
render 'assignments/show'expect(response).not_to be_nil # have_tag()endend

# File: apps/canvas-lms/spec/views/assignments/show_locked.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/assignments/show_locked"do
it "should render"do
course_with_teacher
view_context(@course,@user)
assigns[:assignment]=@course.assignments.create!(:title=>"some assignment")
render 'assignments/show_locked'expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/assignments/syllabus.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/assignments/syllabus"do
it "should render"do
course_with_student
view_context(@course,@user)
assigns[:events]=[@course.assignments.create!(:title=>"some assignment",:due_at=>Time.now),@course.calendar_events.create!(:title=>"some event",:start_at=>Time.now,:end_at=>Time.now)]
assigns[:dates]= assigns[:events].map{|e| e.start_at}
assigns[:undated_events]=[@course.assignments.create!(:title=>"assignment 2"),@course.calendar_events.create!(:title=>"event 2")]
render 'assignments/syllabus'expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/assignments/text_entry_page.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/assignments/text_entry_page"do
it "should render"do
course_with_student
view_context(@course,@user)
assigns[:assignment]=@course.assignments.create!(:title=>"some assignment")
assigns[:submission]= assigns[:assignment].submit_homework(@user)
render 'assignments/text_entry_page'expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/calendars/_event.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/calendars/_event"do
it "should render"do
course_with_student
view_context(@course,@user)
render :partial=>'calendars/event',:object=>@course.calendar_events.create!(:title=>"some event")expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/calendars/_mini_calendar.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/calendars/_mini_calendar"do
it "should render"do
today =Time.zone.today
render :partial=>'calendars/mini_calendar',:locals=>{:current=> today,:first_day=> today -3,:last_day=> today +30}expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/collaborations/index.html.erb_spec.rb## Copyright (C) 2011-2012 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/collaborations/index"do
before do
course_with_student
view_context(@course,@user)
assigns[:collaborations]=[@course.collaborations.create!(user:@user, title:"my collab!")]end
it "should render"do
render 'collaborations/index'expect(response).not_to be_nil
end
it "should provide labels for accessibility devices i.e. screen readers"do
render :partial=>"collaborations/forms"expect(response).not_to be_nil
expect(response).to have_tag("label[for=collaboration_title]",:text=>"Document name:")expect(response).to have_tag("label[for=collaboration_description]",:text=>"Description:")expect(response).to have_tag("label[for=collaboration_collaboration_type]",:text=>"Collaborate using:")endend

# File: apps/canvas-lms/spec/views/conferences/index.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/conference/index"do
before do# these specs need an enabled web conference plugin@plugin=PluginSetting.create!(name:'wimba')@plugin.update_attribute(:settings,{:domain=>'www.example.com'})end
it "should render"docourse_with_teacher(:active_all=>true)view_context(@course,@user)@conference=@course.web_conferences.build(:conference_type=>"Wimba")@conference.user =@user@conference.save!@conference.add_initiator(@user)
assigns[:conferences]=[@conference]
assigns[:users]=@course.users
render "conferences/index"expect(response).to have_tag("#new-conference-list")endend

# File: apps/canvas-lms/spec/views/context/undelete_index.html.erb_spec.rb## Copyright (C) 2014 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "context/undelete_index.html.erb"do
before docourse_with_teacher(:active_all=>true)
assigns[:context]=@courseend
it "should render the undelete link correctly for quizzes"do
quiz =@course.quizzes.create!
assigns[:deleted_items]=[quiz]
render
expect(response.body).not_to match /quizzes:quiz/expect(response.body).to match /quiz_#{quiz.id}/endend

# File: apps/canvas-lms/spec/views/context_modules/index.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/context_modules/index"do
before :eachdo
assigns[:body_classes]=[]
assigns[:menu_tools]=Hash.new([])
assigns[:collapsed_modules]=[]end
it "should render"do
course
view_context(@course,@user)
assigns[:modules]=@course.context_modules.active
render 'context_modules/index'expect(response).not_to be_nil
end
it "should show content_tags"do
course
context_module =@course.context_modules.create!
content_tag = context_module.add_item :type=>'context_module_sub_header'
content_tag.publish!if content_tag.unpublished?view_context(@course,@user)
assigns[:modules]=@course.context_modules.active
render 'context_modules/index'expect(response).not_to be_nil
page =Nokogiri('<document>'+ response.body +'</document>')expect(page.css("#context_module_item_#{content_tag.id}").length).to eq 1end
it "should show unpublished content_tags"docourse_with_teacher(:active_all=>true)
wiki_page =wiki_page_model(:course=>@course)
wiki_page.workflow_state ='unpublished'
wiki_page.save!
context_module =@course.context_modules.create!
content_tag = context_module.add_item(:type=>'wiki_page',:id=> wiki_page.id)expect(content_tag.workflow_state).to eq 'unpublished'view_context(@course,@user)
assigns[:modules]=@course.context_modules.active
render 'context_modules/index'expect(response).not_to be_nil
page =Nokogiri('<document>'+ response.body +'</document>')expect(page.css("#context_module_item_#{content_tag.id}").length).to eq 1end
it "should not show deleted content_tags"do
course
context_module =@course.context_modules.create!
content_tag = context_module.add_item :type=>'context_module_sub_header'
content_tag.destroy
view_context(@course,@user)
assigns[:modules]=@course.context_modules.active
render 'context_modules/index'expect(response).not_to be_nil
page =Nokogiri('<document>'+ response.body +'</document>')expect(page.css("#context_module_item_#{content_tag.id}").length).to eq 0endend

# File: apps/canvas-lms/spec/views/context_modules/url_show.html.erb_spec.rb## Copyright (C) 2012 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/context_modules/url_show"do
it "should render"do
course
view_context(@course,@user)@module=@course.context_modules.create!(:name=>'teh module')@tag=@module.add_item(:type=>'external_url',:url=>'http://example.com/lolcats',:title=>'pls view')
assigns[:module]=@module
assigns[:tag]=@tag
render 'context_modules/url_show'
doc =Nokogiri::HTML.parse(response.body)expect(doc.at_css('iframe')['src']).to eq 'http://example.com/lolcats'expect(doc.css('a').collect{|a|[a['href'], a.inner_text]}).to be_include ['http://example.com/lolcats','pls view']endend

# File: apps/canvas-lms/spec/views/courses/_recent_event.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/courses/_recent_event"do
it "should render"do
course_with_student
assignment =@course.assignments.create!(:title=>'my assignment')
view_context
render :partial=>"courses/recent_event",:object=> assignment,:locals=>{:is_hidden=>false}expect(response).not_to be_nil
expect(response.body).to match %r{<b>my assignment</b>}end
it "should render without a user"do
course
assignment =@course.assignments.create!(:title=>'my assignment')
view_context
render :partial=>"courses/recent_event",:object=> assignment,:locals=>{:is_hidden=>false}expect(response).not_to be_nil
expect(response.body).to match %r{<b>my assignment</b>}end
context "assignment muting and tooltips"dobefore(:each)do
course_with_student
view_context
@quiz=@course.quizzes.create!@quiz.generate_quiz_data
@quiz.workflow_state ='available'@quiz.published_at =Time.now
@quiz.save
expect(@quiz.assignment).not_to be_nil
@quiz_submission=@quiz.generate_submission(@user)Quizzes::SubmissionGrader.new(@quiz_submission).grade_submission
@submission=@quiz_submission.submission
Submission.any_instance.stubs(:score).returns(1234567890987654400)end
it "should show the score for a non-muted assignment"do
render :partial=>"courses/recent_event",:object=>@quiz.assignment,:locals=>{:is_hidden=>false,:submissions=>[@submission]}expect(response.body).to match /#{@submission.score}/end
it "should not show the score for a muted assignment"do@quiz.assignment.mute!
render :partial=>"courses/recent_event",:object=>@quiz.assignment,:locals=>{:is_hidden=>false,:submissions=>[@submission]}expect(response.body).not_to match /#{@submission.score}/endendend# Sidebar content

# File: apps/canvas-lms/spec/views/courses/index.html.erb_spec.rb## Copyright (C) 2014 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/courses/index"do
it "should render"do
course_with_student
view_context
assigns[:current_enrollments]=[@enrollment]
assigns[:past_enrollments]=[]
assigns[:future_enrollments]=[]
assigns[:visible_groups]=[]
render "courses/index"expect(response).not_to be_nil
end
it "should show context name under group name"do
course_with_student
group_with_user(:user=>@user,:group_context=>@course)
view_context
assigns[:current_enrollments]=[@enrollment]
assigns[:past_enrollments]=[]
assigns[:future_enrollments]=[]
assigns[:visible_groups]=[@group]
render "courses/index"
doc =Nokogiri::HTML.parse(response.body)expect(doc.at_css('#my_groups_table tr:first span.subtitle').text).to eq @course.nameendend

# File: apps/canvas-lms/spec/views/courses/settings_sidebar.html.erb_spec.rb## Copyright (C) 2012 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "courses/_settings_sidebar.html.erb"do
before docourse_with_teacher(:active_all=>true)@course.sis_source_id ="so_special_sis_id"@course.workflow_state ='claimed'@course.save!
assigns[:context]=@course
assigns[:user_counts]={}
assigns[:all_roles]=Role.custom_roles_and_counts_for_course(@course,@user)
assigns[:course_settings_sub_navigation_tools]=[]end
describe "End this course button"do
it "should not display if the course or term end date has passed"do@course.stubs(:soft_concluded?).returns(true)view_context(@course,@user)
assigns[:current_user]=@user
render
expect(response.body).not_to match(/Conclude this Course/)end
it "should display if the course and its term haven't ended"do@course.stubs(:soft_concluded?).returns(false)view_context(@course,@user)
assigns[:current_user]=@user
render
expect(response.body).to match(/Conclude this Course/)endend
describe "Reset course content"do
it "should not display the dialog contents under the button"doview_context(@course,@user)
assigns[:current_user]=@user
render
doc =Nokogiri::HTML.parse(response.body)expect(doc.at_css('#reset_course_content_dialog')['style']).to eq 'display:none;'endend
describe "course settings sub navigation external tools"dodefcreate_course_settings_sub_navigation_tool(options ={})@course.root_account.enable_feature!(:lor_for_account)
defaults ={
name: options[:name]||"external tool",
consumer_key:'test',
shared_secret:'asdf',
url:'http://example.com/ims/lti',
course_settings_sub_navigation:{ icon_url:'/images/delete.png'},}@course.context_external_tools.create!(defaults.merge(options))end
before doview_context(@course,@user)
assigns[:current_user]=@userend
it "should display all configured tools"do
num_tools =3(1..num_tools).eachdo|n|create_course_settings_sub_navigation_tool(name:"tool #{n}")end
assigns[:course_settings_sub_navigation_tools]=@course.context_external_tools.to_a
render
doc =Nokogiri::HTML.parse(response.body)expect(doc.css('.course-settings-sub-navigation-lti').size).to eq num_tools
end
it "should include the launch type parameter"do
create_course_settings_sub_navigation_tool
assigns[:course_settings_sub_navigation_tools]=@course.context_external_tools.to_a
render
doc =Nokogiri::HTML.parse(response.body)
tool_link = doc.at_css('.course-settings-sub-navigation-lti')expect(tool_link['href']).to include("launch_type=course_settings_sub_navigation")endendend

# File: apps/canvas-lms/spec/views/discussion_topics/_entry.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/discussion_topics/_entry"do
it "should render"do
course_with_teacher
view_context(@course,@user)@topic=@course.discussion_topics.create!(:title=>"some title")@topic.context
assigns[:entries]=[]
assigns[:topic]=@topic
render :partial=>"discussion_topics/entry",:object=>nil,:locals=>{:topic=>@topic}end
it "should render with data"do
course_with_teacher
view_context(@course,@user)@topic=@course.discussion_topics.create!(:title=>"some title")@topic.context
@entry=@topic.discussion_entries.create!(:message=>"some message")@entry.context
assigns[:entries]=[@entry]
assigns[:grouped_entries]=[@entry].group_by(&:parent_id)
assigns[:topic]=@topic
render :partial=>"discussion_topics/entry",:object=>@entry,:locals=>{:topic=>@topic}endend

# File: apps/canvas-lms/spec/views/discussion_topics/index.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/discussion_topics/index"do
it "should render"do
course_with_teacher
view_context(@course,@user)
assigns[:body_classes]=[]
render "discussion_topics/index"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/discussion_topics/show.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/discussion_topics/show"do
it "should render"do
course_with_teacher
view_context(@course,@user)@topic=@course.discussion_topics.create!(:title=>"some topic",:user=>@user)@entry=@topic.discussion_entries.create!(:message=>"some message")@topic.discussion_entries.create!(:message=>"another message")
assigns[:topic]=@topic
assigns[:grouped_entries]=@topic.discussion_entries.group_by(&:parent_id)
assigns[:entries]=@topic.discussion_entries
assigns[:all_entries]=@topic.discussion_entries
assigns[:presenter]=DiscussionTopicPresenter.new(@topic,@user)
render "discussion_topics/show"expect(response).to have_tag("div#discussion_subentries")end
it "should render in a group context"doassignment_model(:submission_types=>'discussion_topic')rubric_association_model(:association_object=>@assignment,:purpose=>'grading')
group_model
view_context(@group,@user)@topic=@assignment.discussion_topic
@topic.user =@user@topic.save!@entry=@topic.discussion_entries.create!(:message=>"some message")@topic.discussion_entries.create!(:message=>"another message")
assigns[:topic]=@topic
assigns[:grouped_entries]=@topic.discussion_entries.group_by(&:parent_id)
assigns[:entries]=@topic.discussion_entries
assigns[:all_entries]=@topic.discussion_entries
assigns[:assignment]=AssignmentOverrideApplicator.assignment_overridden_for(@assignment,@user)
assigns[:presenter]=DiscussionTopicPresenter.new(@topic,@user)expect(@topic.for_assignment?).to be_truthy
expect(@topic.assignment.rubric_association.rubric).not_to be_nil
render "discussion_topics/show"expect(response).to have_tag("div#discussion_subentries")endend

# File: apps/canvas-lms/spec/views/enrollment_terms/index.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "terms/_term.html.erb"do
describe "sis_source_id edit box"do
before do@account=Account.default
@term=@account.enrollment_terms.create(:name=>"test term")@term.sis_source_id ="sis_this_fool"
assigns[:context]=@account
assigns[:account]=@account
assigns[:root_account]=@account
assigns[:course_counts_by_term]=EnrollmentTerm.course_counts([@term])
assigns[:user_counts_by_term]=EnrollmentTerm.user_counts(@account,[@term])end
it "should show to sis admin"do
admin = account_admin_user
view_context(@account, admin)
assigns[:current_user]= admin
render :partial=>"terms/term.html.erb",:locals=>{:term=>@term}expect(response).to have_tag("input#enrollment_term_sis_source_id")end
it "should not show to non-sis admin"do
admin =account_admin_user_with_role_changes(:role_changes=>{'manage_sis'=>false})view_context(@account, admin)
assigns[:current_user]= admin
render :partial=>"terms/term.html.erb",:locals=>{:term=>@term}expect(response).not_to have_tag("input#enrollment_term_sis_source_id")expect(response).to have_tag("span.sis_source_id",@term.sis_source_id)endendend

# File: apps/canvas-lms/spec/views/eportfolios/_page_list.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/eportfolios/_page_list"do
it "should render"do
eportfolio_with_user
view_portfolio
assigns[:category]=@portfolio.eportfolio_categories.create!(:name=>"some category")
assigns[:page]=@portfolio.eportfolio_entries.create!(:name=>"some entry",:eportfolio_category=> assigns[:category])
render :partial=>"eportfolios/page_list"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/eportfolios/_page_section.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/eportfolios/_page_section"do
it "should render"do
eportfolio_with_user
view_portfolio
assigns[:category]=@portfolio.eportfolio_categories.create!(:name=>"some category")
assigns[:page]=@portfolio.eportfolio_entries.create!(:name=>"some entry",:eportfolio_category=> assigns[:category])
render :partial=>"eportfolios/page_section",:object=>{"section_type"=>"rich_text","content"=>"some text"},:locals=>{:idx=>0}expect(response).to have_tag("div.section")endend

# File: apps/canvas-lms/spec/views/eportfolios/_section_list.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/eportfolios/_section_list"do
it "should render"do
eportfolio_with_user
view_portfolio
assigns[:category]=@portfolio.eportfolio_categories.create!(:name=>"some category")
assigns[:categories]=[assigns[:category]]
assigns[:page]=@portfolio.eportfolio_entries.create!(:name=>"some entry",:eportfolio_category=> assigns[:category])
render :partial=>"eportfolios/section_list"expect(response).to have_tag("ul#section_list")endend

# File: apps/canvas-lms/spec/views/eportfolios/show.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/eportfolios/show"do
before do
eportfolio_with_user
view_portfolio
assigns[:category]=@portfolio.eportfolio_categories.create!(:name=>"some category")
assigns[:categories]=[assigns[:category]]
assigns[:recent_submissions]=[]
assigns[:folders]=[]
assigns[:files]=[]
assigns[:page]=@portfolio.eportfolio_entries.create!(:name=>"some entry",:eportfolio_category=> assigns[:category])end
it "should render"do
render "eportfolios/show"expect(response).not_to be_nil
end
it "should not link the user name if @owner_url is not set"do
render "eportfolios/show"expect(view.content_for(:left_side)[/<a [^>]*id="section-tabs-header-subtitle"/]).to be_nil
expect(view.content_for(:left_side)[/<span [^>]*id="section-tabs-header-subtitle"/]).not_to be_nil
end
it "should link the user name if @owner_url is set"do
assigns[:owner_url]=user_url(@portfolio.user)
render "eportfolios/show"expect(view.content_for(:left_side)[assigns[:owner_url]]).not_to be_nil
expect(view.content_for(:left_side)[/<a [^>]*id="section-tabs-header-subtitle"/]).not_to be_nil
expect(view.content_for(:left_side)[/<span [^>]*id="section-tabs-header-subtitle"/]).to be_nil
end
it "should show the share link explicitly"do
assigns[:owner_view]=true
render "eportfolios/show"
doc =Nokogiri::HTML.parse(response.body)expect(doc.at_css('#eportfolio_share_link').text).to match %r{https?://.*/eportfolios/#{@portfolio.id}\?verifier=.*}end
it "shows the right submission preview link"docourse_with_student(user:@user)submission_model(course:@course, user:@user)
assigns[:owner_view]=true
render "eportfolios/show"
doc =Nokogiri::HTML.parse(response.body)expect(doc.at_css("#recent_submission_#{@submission.id} .view_submission_url").attributes['href'].value).to match(%r{/courses/#{@course.id}/assignments/#{@assignment.id}/submissions/#{@user.id}})endend

# File: apps/canvas-lms/spec/views/eportfolios/user_index.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/eportfolios/index"do
it "should render"do
eportfolio_with_user
view_portfolio
assigns[:portfolios]=[@portfolio]
render "eportfolios/user_index"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/files/_content_folder.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/files/_content_folder"do
it "should render"do
course_with_student
view_context
render :partial=>"files/content_folder"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/files/_folder.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/files/_folder"do
it "should render"do
course_with_student
view_context
render :partial=>"files/folder"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/files/_nested_content.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/files/_nested_content"do
it "should render"do
course_with_student
view_context
render :partial=>"files/nested_content",:object=>[]expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/files/new.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/files/index"do
it "should render"do
course_with_student
view_context
assigns[:attachment]=@course.attachments.create!(:uploaded_data=> default_uploaded_data)
render "files/new"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/files/show.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/files/index"do
it "should render"do
course_with_student
view_context
assigns[:attachment]=@course.attachments.create!(:uploaded_data=> default_uploaded_data)
render "files/show"expect(response).not_to be_nil
end
it "should display a message that the file is locked if user is a student and the file is locked/unpublished"do
course_with_student
view_context
attachment =@course.attachments.create!(:uploaded_data=> default_uploaded_data)
attachment.locked =true
attachment.save!
assigns[:attachment]= attachment
render "files/show"expect(rendered).to match /This file is currently locked/endend

# File: apps/canvas-lms/spec/views/gradebooks/_grading_box.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/gradebooks/_grading_box"do
it "should render"do
course_with_student
view_context
a =@course.assignments.create!(:title=>"some assignment")
render :partial=>"gradebooks/grading_box",:object=> a
expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/gradebooks/blank_submission.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/gradebooks/blank_submission"do
it "should render"do
render "gradebooks/blank_submission"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/gradebooks/grade_summary.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/gradebooks/grade_summary"do
it "should render"do
course_with_student
view_context
a =@course.assignments.create!(:title=>"some assignment")
assigns[:presenter]=GradeSummaryPresenter.new(@course,@user,nil)
render "gradebooks/grade_summary"expect(response).not_to be_nil
end
it "should not show totals if configured so"do
course_with_student
@course.hide_final_grades =true
view_context
a =@course.assignments.create!(:title=>"some assignment")
assigns[:presenter]=GradeSummaryPresenter.new(@course,@user,nil)
render "gradebooks/grade_summary"expect(response).not_to be_nil
page =Nokogiri('<document>'+ response.body +'</document>')expect(page.css(".final_grade").length).to eq 0end
it "should not show 'what if' if not the student"do
course_with_teacher
student_in_course
@student=@user@user=@teacher
view_context
a =@course.assignments.create!(:title=>"some assignment")
assigns[:presenter]=GradeSummaryPresenter.new(@course,@teacher,@student.id)expect(assigns[:presenter].student_enrollment).not_to be_nil
render "gradebooks/grade_summary"expect(response).not_to be_nil
expect(response.body).not_to match(/Click any score/)end
it "should know the types of media comments"do
stub_kaltura
course_with_teacher
student_in_course
view_context
a =@course.assignments.create!(:title=>'some assignment',:submission_types=>['online_text_entry'])
sub = a.submit_homework @student,:submission_type=>"online_text_entry",:body=>"o hai"
sub.add_comment :author=>@teacher,:media_comment_id=>'0_abcdefgh',:media_comment_type=>'audio'
sub.add_comment :author=>@teacher,:media_comment_id=>'0_ijklmnop',:media_comment_type=>'video'
assigns[:presenter]=GradeSummaryPresenter.new(@course,@teacher,@student.id)
render "gradebooks/grade_summary"
doc =Nokogiri::HTML::DocumentFragment.parse response.body
expect(doc.at_css('.audio_comment ~ span.media_comment_id').text).to eql '0_abcdefgh'expect(doc.at_css('.video_comment ~ span.media_comment_id').text).to eql '0_ijklmnop'end
it "should show a disabled message for grade stats for the test student"docourse_with_teacher(:active_all=>true)@student=@course.student_view_student
@user=@teacher
view_context
a =@course.assignments.create!(:title=>"some assignment",:points_possible=>10)
a.grade_student(@student, grade:"10")
assigns[:presenter]=GradeSummaryPresenter.new(@course,@teacher,@student.id)
render "gradebooks/grade_summary"expect(response).not_to be_nil
expect(response.body).to match(/Test Student scores are not included in grade statistics./)endend

# File: apps/canvas-lms/spec/views/gradebooks/grade_summary_list.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/gradebooks/grade_summary_list"do
it "should render"do
render "gradebooks/grade_summary_list"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/gradebooks/gradebook2.html.erb_spec.rb## Copyright (C) 2014 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/gradebooks/gradebook2"dodeftest_grade_publishing(course_allows, permissions_allow)
course_with_student
view_context
a =@course.assignments.create!(:title=>"some assignment")
assigns[:assignments]=[a]
assigns[:students]=[@user]
assigns[:submissions]=[]
assigns[:gradebook_upload]=''
assigns[:body_classes]=[]
assigns[:post_grades_tools]=[]if course_allows && permissions_allow
assigns[:post_grades_tools]=[{type::post_grades}]end@course.expects(:allows_grade_publishing_by).with(@user).returns(course_allows)@course.expects(:grants_any_right?).returns(permissions_allow)if course_allows
render "/gradebooks/gradebook2"expect(response).not_to be_nil
if course_allows && permissions_allow
expect(response.body).to match /Publish grades to SIS/elseexpect(response.body).not_to match /Publish grades to SIS/endend
it "should enable grade publishing when appropriate"dotest_grade_publishing(true,true)end
it "should disable grade publishing when the course disallows it"dotest_grade_publishing(false,true)end
it "should disable grade publishing when permissions disallow it"dotest_grade_publishing(true,false)end
describe "uploading scores"do
before :eachdocourse_with_teacher(:active_all=>true)
view_context
assigns[:gradebook_is_editable]=true
assigns[:assignments]=[]
assigns[:students]=[]
assigns[:submissions]=[]
assigns[:gradebook_upload]=''
assigns[:body_classes]=[]
assigns[:post_grades_tools]=[]end
it "should allow uploading scores for courses"do
render "/gradebooks/gradebook2"expect(response).not_to be_nil
expect(response.body).to match /Import/end
it "should not allow uploading scores for large roster courses"do@course.large_roster =true@course.save!@course.reload
render "/gradebooks/gradebook2"expect(response).not_to be_nil
expect(response.body).not_to match /Import/endendend

# File: apps/canvas-lms/spec/views/gradebooks/speed_grader.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/gradebooks/speed_grader"do
before do
course_with_student
view_context
assigns[:students]=[@user]
assigns[:assignment]=@course.assignments.create!(:title=>"some assignment")
assigns[:submissions]=[]
assigns[:assessments]=[]
assigns[:body_classes]=[]end
it "should render"do
render "gradebooks/speed_grader"expect(response).not_to be_nil
end
it "includes a link back to the gradebook (gradebook2 by default)"do
render "gradebooks/speed_grader"
course_id =@course.id
expect(response.body).to include "a href=\"http://test.host/courses/#{course_id}/gradebook\""endend

# File: apps/canvas-lms/spec/views/groups/_category.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/groups/_category"do
it "should render"do
course_with_student
view_context
assigns[:groups]=[]
category =@course.group_categories.create(:name=>"Good Students")
render :partial=>"groups/category",:object=> category
expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/groups/_student.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/groups/_student"do
it "should render"do
course_with_student
@group=@course.groups.create!(:name=>"some group")
assigns[:memberships]=[]view_context(@user,@group)
render :partial=>"groups/student",:object=>@userexpect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/groups/context_groups.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/groups/context_groups"do
it "should render"do
course_with_student
view_context
render "groups/context_groups"expect(response).not_to be_nil
end
it "should render for an account"doview_context(Account.default)
render "groups/context_groups"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/groups/context_manage_groups.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/groups/context_manage_groups"do
it "should render"do
course_with_student
view_context
assigns[:categories]=[]
assigns[:students]=[@user]
assigns[:memberships]=[]
assigns[:groups]=[]
render "groups/context_manage_groups"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/groups/index.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/groups/index"do
it "should render"do
course_with_student
view_context
assigns[:categories]=[]
assigns[:students]=[@user]
assigns[:memberships]=[]
assigns[:groups]=[]
render "groups/index"expect(response).not_to be_nil
end
it "should show context name under group name"do
course_with_student
group_with_user(:user=>@user,:group_context=>@course)
view_context
assigns[:categories]=[]
assigns[:students]=[@user]
assigns[:memberships]=[]
assigns[:groups]=[@group]
render "groups/index"
doc =Nokogiri::HTML.parse(response.body)expect(doc.at_css('ul.context_list li:first span.subtitle').text).to eq @course.name
endend

# File: apps/canvas-lms/spec/views/groups/show.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/groups/show"do
it "should render"do
course_with_student
@group=@course.groups.create!(:name=>"some group")view_context(@group,@user)
assigns[:group]=@group
assigns[:topics]=[]
assigns[:upcoming_events]=[]
assigns[:context]=@group
assigns[:stream_items]=[]
render "groups/show"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/layouts/application.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')
describe "layouts/application"do
it "should render"do
assigns[:domain_root_account]=Account.default
render "layouts/application"endend

# File: apps/canvas-lms/spec/views/login/canvas/new.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#
require_relative '../../../spec_helper'
require_relative '../../views_helper'
describe "login/canvas/new.html.erb"do
before do
assigns[:domain_root_account]=Account.default
end
it "uses canvas route by default"do
render
expect(response).not_to be_nil
doc =Nokogiri::HTML(response.body)expect(doc.at_css('form#login_form')['action']).to eq '/login/canvas'end
it "uses ldap route for the ldap 'controller'"doAccount.default.authentication_providers.create!(:auth_type=>'ldap')
controller.request.path_parameters[:controller]='login/ldap'
render
expect(response).not_to be_nil
doc =Nokogiri::HTML(response.body)expect(doc.at_css('form#login_form')['action']).to eq '/login/ldap'end
it "should use internal forgot password mechanism by default"do
render
page =Nokogiri(response.body)expect(page.css("#login_forgot_password")[0]['href']).to eq '#'end
context "with external mechanism specified"dolet(:account){Account.default }let(:config){ account.authentication_providers.build }
before do
config.auth_type ='ldap'
config.save!
account.change_password_url ="http://www.instructure.com"
account.save!expect(account.forgot_password_external_url).
to eq(account.change_password_url)
assigns[:domain_root_account]= account
end
it "should use external forgot password mechanism"do
render
page =Nokogiri(response.body)expect(page.css("#login_forgot_password")[0]['href']).
to eq(account.change_password_url)endendend

# File: apps/canvas-lms/spec/views/profile/_email_select.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/profile/_email_select"do
it "should render"do
course_with_student
view_context
cc =@user.communication_channels.create!(:path=>'user@example.com')
assigns[:email_channels]=[cc]
render :partial=>"profile/email_select",:object=> cc
expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/profile/_secondary_nav.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/profile/_secondary_nav"do
it "should render"do
course_with_student
view_context
render :partial=>"profile/secondary_nav"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/profile/_sms_select.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/profile/_sms_select"do
it "should render"do
course_with_student
view_context
cc =@user.communication_channels.create!(:path=>'user@example.com')
assigns[:other_channels]=[cc]
assigns[:sms_channels]=[]
render :partial=>"profile/sms_select",:object=> cc
expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/profile/_ways_to_contact.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/profile/_ways_to_contact"do
it "should render"do
course_with_student
view_context
assigns[:email_channels]=[]
assigns[:other_channels]=[]
assigns[:sms_channels]=[]
assigns[:user]=@user
render :partial=>"profile/ways_to_contact"expect(response).not_to be_nil
end
it "should not show a student the confirm link"do
course_with_student
view_context
@user.communication_channels.create!(:path_type=>'email',:path=>'someone@somewhere.com')expect(@user.communication_channels.first.state).to eq :unconfirmed
assigns[:email_channels]=@user.communication_channels.to_a
assigns[:other_channels]=[]
assigns[:sms_channels]=[]
assigns[:user]=@user
render :partial=>"profile/ways_to_contact"expect(response.body).not_to match /confirm_channel_link/end
it "should show an admin the confirm link"do
account_admin_user
view_context
@user.communication_channels.create!(:path_type=>'email',:path=>'someone@somewhere.com')expect(@user.communication_channels.first.state).to eq :unconfirmed
assigns[:email_channels]=@user.communication_channels.to_a
assigns[:other_channels]=[]
assigns[:sms_channels]=[]
assigns[:user]=@user
render :partial=>"profile/ways_to_contact"expect(response.body).to match /confirm_channel_link/end
it "should not show confirm link for confirmed channels"do
account_admin_user
view_context
@user.communication_channels.create!(:path_type=>'email',:path=>'someone@somewhere.com')@user.communication_channels.first.confirm
expect(@user.communication_channels.first.state).to eq :active
assigns[:email_channels]=@user.communication_channels.to_a
assigns[:other_channels]=[]
assigns[:sms_channels]=[]
assigns[:user]=@user
render :partial=>"profile/ways_to_contact"expect(response.body).not_to match /confirm_channel_link/end
it "should show an admin masquerading as a user the confirm link"do
course_with_student
account_admin_user
view_context(@course,@student,@admin)@student.communication_channels.create!(:path_type=>'email',:path=>'someone@somewhere.com')expect(@student.communication_channels.first.state).to eq :unconfirmed
assigns[:email_channels]=@student.communication_channels.to_a
assigns[:other_channels]=[]
assigns[:sms_channels]=[]
assigns[:user]=@student
render :partial=>"profile/ways_to_contact"expect(response.body).to match /confirm_channel_link/end
it 'should not show the "I want to log in" for non-default accounts'do
course_with_student
view_context
assigns[:email_channels]=[]
assigns[:other_channels]=[]
assigns[:sms_channels]=[]
assigns[:user]=@user
assigns[:domain_root_account]=Account.create!
render :partial=>"profile/ways_to_contact"expect(response.body).not_to match /I want to log in to Canvas using this email address/endend

# File: apps/canvas-lms/spec/views/profile/communication.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/profile/communication"do
it "should render"do
course_with_student
communication_channel(@user)
view_context
assigns[:email_channels]=[]
assigns[:other_channels]=[]
assigns[:sms_channels]=[]
assigns[:notification_categories]=Notification.dashboard_categories
assigns[:policies]=NotificationPolicy.for(@user)
assigns[:user]=@user
render "profile/communication"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/profile/profile.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/profile/profile"do
it "should render"docourse_with_student(:active_user=>true)
view_context
assigns[:user]=@user
assigns[:email_channels]=[]
assigns[:other_channels]=[]
assigns[:sms_channels]=[]
assigns[:notification_categories]=Notification.dashboard_categories
assigns[:policies]=NotificationPolicy.for(@user)
assigns[:default_pseudonym]=@user.pseudonyms.create!(:unique_id=>"unique@example.com",:password=>"asdfaa",:password_confirmation=>"asdfaa")
assigns[:pseudonyms]=@user.pseudonyms
assigns[:password_pseudonyms]=[]
render "profile/profile"expect(response).not_to be_nil
end
it "should not show the delete link for SIS pseudonyms without manage_sis"doaccount_admin_user_with_role_changes(active_user:true, role_changes:{manage_sis:false})
view_context
assigns[:user]=@user
assigns[:email_channels]=[]
assigns[:other_channels]=[]
assigns[:sms_channels]=[]
assigns[:notification_categories]=Notification.dashboard_categories
assigns[:policies]=NotificationPolicy.for(@user)
default_pseudonym = assigns[:default_pseudonym]=@user.pseudonyms.create!(:unique_id=>"unique@example.com",:password=>"asdfaa",:password_confirmation=>"asdfaa")
sis_pseudonym =@user.pseudonyms.create!(:unique_id=>'sis_unique@example.com'){|p| p.sis_user_id ='sis_id'}
assigns[:pseudonyms]=@user.pseudonyms
assigns[:password_pseudonyms]=[]
render "profile/profile"
page =Nokogiri('<document>'+ response.body +'</document>')expect(page.css("#pseudonym_#{default_pseudonym.id} .delete_pseudonym_link").first['style']).to eq ''expect(page.css("#pseudonym_#{sis_pseudonym.id} .delete_pseudonym_link").first['style']).to eq 'display: none;'end
it "should not show the pseudonym delete link to non-admins"docourse_with_student(:active_user=>true)
view_context
assigns[:user]=@user
assigns[:email_channels]=[]
assigns[:other_channels]=[]
assigns[:sms_channels]=[]
assigns[:notification_categories]=Notification.dashboard_categories
assigns[:policies]=NotificationPolicy.for(@user)
default_pseudonym = assigns[:default_pseudonym]=@user.pseudonyms.create!(:unique_id=>"unique@example.com",:password=>"asdfaa",:password_confirmation=>"asdfaa")
assigns[:pseudonyms]=@user.pseudonyms
assigns[:password_pseudonyms]=[]
render "profile/profile"
page =Nokogiri('<document>'+ response.body +'</document>')expect(page.css("#pseudonym_#{default_pseudonym.id} .delete_pseudonym_link").first['style']).to eq 'display: none;'endend

# File: apps/canvas-lms/spec/views/pseudonyms/confirm_change_password.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/pseudonyms/confirm_change_password"do
it "should render"do
user
assigns[:user]=@user
assigns[:current_user]=@user
assigns[:pseudonym]=@user.pseudonyms.create!(:unique_id=>"unique@example.com",:password=>"asdfaa",:password_confirmation=>"asdfaa")
assigns[:password_pseudonyms]=@user.pseudonyms
assigns[:cc]=@user.communication_channels.create!(:path=>'unique@example.com')
render "pseudonyms/confirm_change_password"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/quizzes/quiz_submissions/show.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quiz_submissions/show"do
it "should render"do
course_with_student
view_context
@submission=mock('Quizzes::QuizSubmission')@submission.stubs(:score).returns(10)@submission.stubs(:data).returns([])@quiz=mock('Quizzes::Quiz')@quiz.stubs(:questions).returns([])@quiz.stubs(:points_possible).returns(10)@quiz.stubs(:stored_questions).returns([])@quiz.stubs(:show_correct_answers?).returns(true)
assigns[:quiz]=@quiz
assigns[:submission]=@submission
render "quizzes/quiz_submissions/show"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/_display_answer.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/_display_answer"do
it "should render"do
course_with_student
view_context
assigns[:quiz]=@course.quizzes.create!
answer ={}
answer[:id]=5
answer[:weight]=100
render :partial=>"quizzes/quizzes/display_answer",:object=> answer,:locals=>{:question_type=>OpenObject.new}expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/_display_question.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/_display_question"do
it "should render"do
course_with_student
view_context
@quiz=@course.quizzes.create!(:title=>"new quiz")@quiz.quiz_questions.create!(:question_data=>{:name=>'LTUE',:points_possible=>1,'question_type'=>'numerical_question','answers'=>{'answer_0'=>{'numerical_answer_type'=>'exact_answer','answer_exact'=>42,'answer_text'=>'','answer_weight'=>'100'}}})@quiz.generate_quiz_data
@quiz.save
@submission=@quiz.generate_submission(@student)@submission.submission_data ={"question_#{@quiz.quiz_data[0][:id]}"=>"42.0"}Quizzes::SubmissionGrader.new(@submission).grade_submission
assigns[:quiz]=@quiz
q =@quiz.stored_questions.first
q[:answers][0].delete(:margin)# sometimes this is missing; see #10785
render :partial=>"quizzes/quizzes/display_question",:object=> q,:locals=>{:user_answer=>@submission.submission_data.find{|a| a[:question_id]== q[:id]},:assessment_results=>true}expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/_form_answer.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/_form_answer"do
it "should render"do
course_with_student
view_context
render :partial=>"quizzes/quizzes/form_answer"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/_form_question.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/_form_question"do
it "should render"do
course_with_student
view_context
assigns[:js_env]={quiz_max_combination_count:200}
render :partial=>"quizzes/quizzes/form_question"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/_multi_answer.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/_multi_answer"do
it "should render"do
course_with_student
view_context
assigns[:quiz]=@course.quizzes.create!
answer ={
id:5,
weight:100,
text:'answer_text'}
question ={
question_text:'question text'}
question_type =OpenObject.newrender:partial=>"quizzes/quizzes/multi_answer",:object=> answer,:locals=>{:question=> question,:question_type=> question_type,:user_answer=>nil}expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/_question_group.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/_question_group"do
it "should render"do
course_with_student
view_context
assigns[:quiz]=@course.quizzes.create!
group ={}
group[:id]=5
group[:questions]=[]
render :partial=>"quizzes/quizzes/question_group",:object=> group,:locals=>{:question_type=>OpenObject.new}expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/_question_statistic.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/_question_statistic"do
it "should render"do
course_with_student
view_context
assigns[:quiz]=@course.quizzes.create!
question ={}
question[:id]=5
question[:answers]=[]
question[:question_type]="multiple_choice_question"
question[:question_name]="title of glory"
question[:unexpected_response_values]=[]
render :partial=>"quizzes/quizzes/question_statistic",:object=> question,:locals=>{:in_group=>true,:ignore_correct_answers=>true}expect(response).not_to be_nil
expect(response.body).to match /title of glory/end
it "should not show the submitter's name on anonymous surveys"do
course_with_student
view_context
assigns[:quiz]=@course.quizzes.create!:anonymous_submissions=>true,:quiz_type=>'graded_survey'
question ={:essay_responses=>[{:text=>"Bacon is delicious",:user_id=>@student.id}],:question_name=>"Question",:id=>1,:unexpected_response_values=>[],}
render :partial=>'quizzes/quizzes/question_statistic',:object=> question
expect(response).not_to be_nil
expect(response.body).not_to include @student.name
end
it "renders a link to download all quiz submissions for file upload questions"do
course_with_student
view_context
question ={question_type:'file_upload_question',
unexpected_response_values:[]}
quiz =@course.quizzes.create
quiz.stubs(:quiz_data).returns [question]
assigns[:quiz]= quiz
render :partial=>'quizzes/quizzes/question_statistic', object: question
expect(response.body).to include "Download All Files"endend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/_quiz_right_side.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/_quiz_right_side"do
it "should render"do
course_with_student
view_context
assigns[:quiz]=@course.quizzes.create!
render :partial=>"quizzes/quizzes/quiz_right_side"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/_quiz_submission.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/_quiz_submission"do
it "should render"do
course_with_student
view_context
assigns[:quiz]=@course.quizzes.create!
assigns[:submission]= assigns[:quiz].generate_submission(@user)Quizzes::SubmissionGrader.new(assigns[:submission]).grade_submission
render :partial=>"quizzes/quizzes/quiz_submission"expect(response).not_to be_nil
end
it "should render when quiz results are not supposed to be shown to the student"do
course_with_student
view_context
quiz =@course.quizzes.create!
quiz.hide_results ='always'
quiz.save!
assigns[:quiz]= quiz
assigns[:submission]= assigns[:quiz].generate_submission(@user)Quizzes::SubmissionGrader.new(assigns[:submission]).grade_submission
render :partial=>"quizzes/quizzes/quiz_submission"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/_quiz_summary.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/_quiz_summary"do
it "should render"do
course_with_student
view_context
assigns[:quiz]=@course.quizzes.create!
assigns[:submissions_hash]={}
render :partial=>"quizzes/quizzes/quiz_summary",:object=> assigns[:quiz]expect(response).not_to be_nil
end
it "should not show scores on muted quizzes"do
course_with_student
view_context
@quiz=@course.quizzes.create!@quiz.generate_quiz_data
@quiz.workflow_state ='available'@quiz.published_at =Time.now
@quiz.save
expect(@quiz.assignment).not_to be_nil
@quiz.assignment.mute!@submission=@quiz.generate_submission(@user)Quizzes::SubmissionGrader.new(@submission).grade_submission
view_context
assigns[:quiz]=@quiz
assigns[:submissions_hash]={@quiz.id =>@submission}
render :partial=>"quizzes/quizzes/quiz_summary",:object=>@quizexpect(response).not_to be_nil
expect(response.body).to match /Instructor is working on grades/endend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/_single_answer.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/_single_answer"do
it "should render"do
course_with_student
view_context
assigns[:quiz]=@course.quizzes.create!
answer =OpenObject.newanswer.id=5
answer.weight =100
question_type =OpenObject.newrender:partial=>"quizzes/quizzes/single_answer",:object=> answer,:locals=>{:question_type=> question_type,:user_answer=>nil}expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/history.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/history"do
before do
course_with_student
view_context
assigns[:user]=@userend
context 'beta quiz navigation'do
before do
assigns[:quiz]=@course.quizzes.create!
assigns[:submission]= assigns[:quiz].generate_submission(@user)
assigns[:current_submission]= assigns[:submission]
assigns[:version_instances]= assigns[:submission].submitted_attempts
end
it 'displays when configured'do@student.preferences[:enable_speedgrader_grade_by_question]=true@student.save!
render "quizzes/quizzes/history"expect(response.body).to match /quiz-nav/end
it "doesn't display when not enabled"do@student.preferences[:enable_speedgrader_grade_by_question]=nil@student.save!
render "quizzes/quizzes/history"expect(response.body).not_to match /quiz-nav/endend
context 'question group warning'do
before do@student.preferences[:enable_speedgrader_grade_by_question]=true@student.save!end
it 'displays when quiz has question groups'do@quiz=@course.quizzes.create!@quiz.quiz_groups.create!
assigns[:quiz]=@quiz
assigns[:submission]= assigns[:quiz].generate_submission(@user)
assigns[:current_submission]= assigns[:submission]
assigns[:version_instances]= assigns[:submission].submitted_attempts
render "quizzes/quizzes/history"expect(response.body).to match /grade-by-question-warning/end
it 'does not display when quiz has only questions'do
assigns[:quiz]=@course.quizzes.create!
assigns[:submission]= assigns[:quiz].generate_submission(@user)
assigns[:current_submission]= assigns[:submission]
assigns[:version_instances]= assigns[:submission].submitted_attempts
render "quizzes/quizzes/history"expect(response.body).not_to match /grade-by-question-warning/endendend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/new.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/new"dodefcourse_quiz(active=false)@quiz=@course.quizzes.create
@quiz.workflow_state ="available"if active
@quiz.save!@quizenddef quiz_question
@quiz.quiz_questions.create
end
it "should render"do
course_with_student
view_context
assigns[:quiz]=@course.quizzes.create!
assigns[:js_env]={quiz_max_combination_count:200}
render "quizzes/quizzes/new"expect(response).not_to be_nil
end
context "with course and quiz"do
before :eachdocourse_with_teacher_logged_in(:active_all=>true)@quiz= course_quiz
assigns[:quiz]=@quiz
assigns[:js_env]={quiz_max_combination_count:200}
view_context
end
it "should not display 'NOTE:' message when questions within limit"doQuizzes::QuizzesController::QUIZ_QUESTIONS_DETAIL_LIMIT.times { quiz_question }
render 'quizzes/quizzes/new'expect(response.inspect).not_to include('NOTE: Question details not available when more than')end
it "should explain why 'Show Question Details' is disabled"do(Quizzes::QuizzesController::QUIZ_QUESTIONS_DETAIL_LIMIT+1).times { quiz_question }
render 'quizzes/quizzes/new'expect(response.inspect).to include('NOTE: Question details not available when more than')end
it 'has a published inditactor when the quiz is published'do@quiz.stubs(:published?).returns true
render 'quizzes/quizzes/new'expect(response.inspect).to include("Published")expect(response.inspect).not_to include("Not Published")end
it 'has a not_published indicator when the quiz is not published'do@quiz.stubs(:published?).returns false
render 'quizzes/quizzes/new'expect(response.inspect).to include("Not Published")endendend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/show.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/show"do
it "should render"do
course_with_student
view_context
assigns[:quiz]=@course.quizzes.create!
render "quizzes/quizzes/show"expect(response).not_to be_nil
end
it "should render a notice instead of grades if muted"docourse_with_student_logged_in(:active_all=>true)
quiz =@course.quizzes.create
quiz.workflow_state ="available"
quiz.save!
quiz.assignment =@course.assignments.create(:title=> quiz.title,:due_at=> quiz.due_at,:submission_types=>'online_quiz')
quiz.assignment.mute!
quiz.assignment.grade_student(@student,:grade=>5)
submission = quiz.quiz_submissions.create
submission.score =5
submission.user =@student
submission.attempt =1
submission.workflow_state ="complete"
submission.save
assigns[:quiz]= quiz
assigns[:submission]= submission
view_context
render "quizzes/quizzes/show"expect(response).to have_tag ".muted-notice"trueend
it "doesn't warn students if quiz is published"docourse_with_student_logged_in(:active_all=>true)
quiz =@course.quizzes.build
quiz.publish!
assigns[:quiz]= quiz
view_context
render "quizzes/quizzes/show"expect(response).not_to have_tag ".unpublished_warning"end
it "should show header bar and publish button"docourse_with_teacher_logged_in(:active_all=>true)
assigns[:quiz]=@course.quizzes.create!
view_context
render "quizzes/quizzes/show"expect(response).to have_tag ".header-bar"expect(response).to have_tag "#quiz-publish-link"end
it "should show unpublished quiz changes to instructors"docourse_with_teacher_logged_in(:active_all=>true)@quiz=@course.quizzes.create!@quiz.workflow_state ="available"@quiz.save!@quiz.publish!Quizzes::Quiz.mark_quiz_edited(@quiz.id)@quiz.reload
assigns[:quiz]=@quiz
view_context
render "quizzes/quizzes/show"expect(response).to have_tag ".unsaved_quiz_warning"expect(response).not_to have_tag ".unpublished_quiz_warning"endend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/statistics.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/statistics"do
it "should render with non-nil submission statistics"do
course_with_student
view_context
assigns[:quiz]= q =@course.quizzes.create!(:quiz_type=>'assignment').tap{|q|expect(q).to be_graded }
assigns[:submitted_users]=[]
assigns[:statistics]={:submission_score_high=>20,:submission_count=>3,:submission_score_low=>15,:multiple_attempts_included=>true,:last_submission_at=>Time.now.utc,:submission_duration_average=>0,:submission_score_stdev=>2.05480466765634,:submission_user_ids=>[4,3,2],:questions=>[],:submission_correct_count_average=>3,:submission_incorrect_count_average=>2,:submission_score_average=>17.3333333333333,:unique_submission_count=>3}
render "quizzes/quizzes/statistics"expect(response).not_to be_nil
expect(content_for(:right_side)).not_to be_nil
kv ={}
page =Nokogiri::HTML(content_for(:right_side))
page.css('#statistics_summary').first.children.each do |row|nextif row.name !='tr'
row = row.children.find_all{|col| col.name =='td'}nextif row.size !=2
kv[row[0].text]= row[1].text
endexpect(kv).to eq({"Low Score:"=>"15","Average Time:"=>"less than a minute","Average Incorrect:"=>"2","Standard Deviation:"=>"2.05","High Score:"=>"20","Mean Score:"=>"17.33","Average Correct:"=>"3"})end
it "should render with nil submission statistics"do
course_with_student
view_context
assigns[:quiz]=@course.quizzes.create!
assigns[:statistics]={:submission_duration_average=>0,:questions=>[]}
assigns[:submitted_users]=[]
render "quizzes/quizzes/statistics"expect(response).not_to be_nil
expect(content_for(:right_side)).not_to be_nil
kv ={}
page =Nokogiri::HTML(content_for(:right_side))
page.css('#statistics_summary').first.children.each do |row|nextif row.name !='tr'
row = row.children.find_all{|col| col.name =='td'}nextif row.size !=2
kv[row[0].text]= row[1].text
endexpect(kv).to eq({"Low Score:"=>"_","Average Time:"=>"less than a minute","Average Incorrect:"=>"_","Standard Deviation:"=>"_","High Score:"=>"_","Mean Score:"=>"_","Average Correct:"=>"_"})endend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/submission_versions.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/submission_versions"do
it "should render"docourse_with_teacher(:active_all=>true)
course_quiz
view_context
assigns[:quiz]=@quiz
assigns[:versions]=[]
render "quizzes/quizzes/submission_versions"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/quizzes/quizzes/take_quiz.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/quizzes/quizzes/take_quiz"do
it "should render"do
course_with_student
view_context
assigns[:quiz]=@course.quizzes.create!(:description=>"Hello")
assigns[:submission]= assigns[:quiz].generate_submission(@user)
assigns[:quiz_presenter]=Quizzes::TakeQuizPresenter.new(assigns[:quiz],
assigns[:submission],
params
)
render "quizzes/quizzes/take_quiz"
doc =Nokogiri::HTML(response.body)expect(doc.css('#quiz-instructions').first.content.strip).to eq "Hello"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/sections/show.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "sections/show.html.erb"do
describe "sis_source_id edit box"do
before docourse_with_teacher(:active_all=>true)@section=@course.course_sections.first
@section.sis_source_id ="section_sissy_id"
assigns[:context]=@course
assigns[:section]=@section
assigns[:enrollments_count]=1
assigns[:student_enrollments_count]=1
assigns[:pending_enrollments_count]=1
assigns[:completed_enrollments_count]=1
assigns[:permission_classes]='manage-permissions'end
it "should not show to teacher"doview_context(@course,@user)
assigns[:current_user]=@user
render
expect(response).to have_tag("span.sis_source_id",@section.sis_source_id)expect(response).not_to have_tag("input#course_section_sis_source_id")end
it "should show to sis admin"do
admin =account_admin_user(:account=>@course.root_account)view_context(@course, admin)
assigns[:current_user]= admin
render
expect(response).to have_tag("input#course_section_sis_source_id")end
it "should not show to non-sis admin"do
admin =account_admin_user_with_role_changes(:account=>@course.root_account,:role_changes=>{'manage_sis'=>false})view_context(@course, admin)
assigns[:current_user]= admin
render
expect(response).not_to have_tag("input#course_section_sis_source_id")expect(response).to have_tag("span.sis_source_id",@section.sis_source_id)endendend

# File: apps/canvas-lms/spec/views/shared/_add_assignment_group.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/shared/_add_assignment_group"do
it "should render"do
course_with_student
view_context
render :partial=>"shared/add_assignment_group"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/shared/_assignment_group.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/shared/_assignment_group"do
it "should render"do
course_with_student
view_context
render :partial=>"shared/assignment_group"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/shared/_discussion_entry.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/shared/_discussion_entry"do
it "should render"do
course_with_student
view_context
render :partial=>"shared/discussion_entry"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/shared/_flash_notices.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/shared/_flash_notices"do
it "should render"do
course_with_student
view_context
render :partial=>"shared/flash_notices"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/shared/_identity.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/shared/_identity"do
it "should render"doSetting.set('show_feedback_link','true')
course_with_student
view_context
render :partial=>"shared/identity"expect(@controller.response).to be_success
end
it "should render without a current user"doSetting.set('show_feedback_link','true')
course_with_student
view_context
assigns.delete(:current_user)
render :partial=>"shared/identity"expect(@controller.response).to be_success
endend

# File: apps/canvas-lms/spec/views/shared/_javascript_init.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/shared/_javascript_init"do
it "should render"do
course_with_student
view_context
render :partial=>"shared/javascript_init"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/shared/_right_side.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/shared/_right_side"do
it "should render"do
course_with_student
view_context
render :partial=>"shared/right_side"expect(response).not_to be_nil
endend# Sidebar content

# File: apps/canvas-lms/spec/views/shared/_select_content_dialog.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/shared/_select_content_dialog"do
it "should include unpublished wiki pages"do
course_with_teacher
published_page =@course.wiki.wiki_pages.build title:'published_page'
published_page.workflow_state ='active'
published_page.save!
unpublished_page =@course.wiki.wiki_pages.build title:'unpublished_page'
unpublished_page.workflow_state ='unpublished'
unpublished_page.save!
view_context
render partial:'shared/select_content_dialog'
page =Nokogiri(response.body)
options = page.css("#wiki_pages_select .module_item_select option")expect(%w(unpublished_page published_page)- options.map(&:text)).to be_empty
end
it "should not offer to create assigments or quizzes if the user doesn't have permission"do@account=Account.default
course_with_ta account:@account, active_all:true
existing_quiz =@course.quizzes.create! title:'existing quiz'@account.role_overrides.create! role: ta_role, permission:'manage_assignments', enabled:false
view_context
render partial:'shared/select_content_dialog'
page =Nokogiri(response.body)expect(page.css(%Q{#quizs_select .module_item_select option[value="#{existing_quiz.id}"]})).not_to be_emptyexpect(page.css(%Q{#quizs_select .module_item_select option[value="new"]})).to be_emptyexpect(page.css(%Q{#assignments_select .module_item_select option[value="new"]})).to be_emptyend
it "should offer to create assigments if the user has permission"do@account=Account.default
course_with_ta account:@account, active_all:true
view_context
render partial:'shared/select_content_dialog'
page =Nokogiri(response.body)expect(page.css(%Q{#assignments_select .module_item_select option[value="new"]})).not_to be_emptyend
it "should create new topics in unpublished state if draft state is enabled"docourse_with_teacher(active_all:true)
view_context
render partial:'shared/select_content_dialog'
page =Nokogiri(response.body)expect(page.at_css(%Q{#discussion_topics_select .new input[name="published"][value="false"]})).not_to be_nilendend

# File: apps/canvas-lms/spec/views/shared/_user_lists.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/shared/_user_lists"do
it "should render as a course"do
assigns[:context]= course
render :partial=>"shared/user_lists"end
it "should render as a root account"do
assigns[:context]=Account.default
render :partial=>"shared/user_lists"end
it "should render as a sub account"do
assigns[:context]=Account.default.sub_accounts.create!
render :partial=>"shared/user_lists"end
it "should render as a root account with customized login handle"doAccount.default.login_handle_name ='Login'Account.default.save!
assigns[:context]=Account.default
render :partial=>"shared/user_lists"endend

# File: apps/canvas-lms/spec/views/shared/_wiki_sidebar.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/shared/_wiki_sidebar"do
it "should render"do
course_with_student
view_context
render :partial=>"shared/wiki_sidebar"expect(response).not_to be_nil
end
it "should render in user context"do
user
view_context(@user,@user)
render :partial=>"shared/wiki_sidebar"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/shared/errors/400_message.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/shared/errors/400_message"do
it "should render"do
course_with_student
view_context
beginnil.bad_method
rescue=> e
assigns[:exception]= e
endActionController::TestResponse.any_instance.stubs(:status).returns(400)
render "shared/errors/400_message"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/shared/errors/404_message.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/shared/errors/404_message"do
it "should render"do
course_with_student
view_context
beginnil.bad_method
rescue=> e
assigns[:exception]= e
end
render "shared/errors/404_message",:locals=>{:exception=> assigns[:exception],:status=>""}expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/shared/errors/500_message.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/shared/errors/500_message"do
it "should render"do
course_with_student
view_context
beginnil.bad_method
rescue=> e
assigns[:exception]= e
endActionController::TestResponse.any_instance.stubs(:status).returns(500)
render "shared/errors/500_message"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/shared/errors/_error_form.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../../views_helper')
describe "/shared/errors/_error_form"do
it "should render"do
course_with_student
view_context
render :partial=>"shared/errors/error_form"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/shared/unauthorized.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/shared/unauthorized"do
it "should render"do
course_with_student
view_context
render "shared/unauthorized"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/submissions/show.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/submissions/show"do
it "should render"do
course_with_student
view_context
a =@course.assignments.create!(:title=>"some assignment")
assigns[:assignment]= a
assigns[:submission]= a.submit_homework(@user)
render "submissions/show"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/submissions/show_preview.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/submissions/show_preview"do
it "should render"do
course_with_student
view_context
a =@course.assignments.create!(:title=>"some assignment")
assigns[:assignment]= a
assigns[:submission]= a.submit_homework(@user)
render "submissions/show_preview"expect(response).not_to be_nil
end
it "should give a user-friendly explaination why there's no preview"do
course_with_student
view_context
a =@course.assignments.create!(:title=>"some assignment",:submission_types=>'on_paper')
assigns[:assignment]= a
assigns[:submission]= a.submit_homework(@user)
render "submissions/show_preview"expect(response.body).to match /No Preview Available/endend

# File: apps/canvas-lms/spec/views/terms/index.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/terms/index"do
it "should allow deletion of terms with only deleted courses"do
assigns[:context]= assigns[:root_account]=Account.default
term =Account.default.enrollment_terms.create!
term.courses.create!{|c| c.workflow_state ='deleted'}
assigns[:terms]=Account.default.enrollment_terms.active.sort_by{|t| t.start_at || t.created_at }.reverse
assigns[:course_counts_by_term]=EnrollmentTerm.course_counts(assigns[:terms])
assigns[:user_counts_by_term]=EnrollmentTerm.user_counts(Account.default, assigns[:terms])
render "terms/index"
page =Nokogiri('<document>'+ response.body +'</document>')expect(page.css(".delete_term_link")[0]['href']).to eq '#'endend

# File: apps/canvas-lms/spec/views/users/_name.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/users/name"do
it "should allow deletes for unmanagaged pseudonyms with correct privileges"do
account_admin_user :account=>Account.default
course_with_student :account=>Account.default
view_context(Account.default,@admin)
assigns[:user]=@student
assigns[:enrollments]=[]
render :partial=>"users/name"expect(response.body).to match /Delete from #{Account.default.name}/end
it "should allow deletes for managaged pseudonyms with correct privileges"do
account_admin_user :account=>Account.default
course_with_student :account=>Account.default
managed_pseudonym(@student,:account=> account_model)view_context(Account.default,@admin)
assigns[:user]=@student
assigns[:enrollments]=[]
render :partial=>"users/name"expect(response.body).to match /Delete from #{Account.default.name}/end
it "should not allow deletes for managed pseudonyms without correct privileges"do@admin= user :account=>Account.default
course_with_student :account=>Account.default
managed_pseudonym(@student,:account=> account_model)view_context(Account.default,@admin)
assigns[:user]=@student
assigns[:enrollments]=[]
render :partial=>"users/name"expect(response.body).not_to match /Delete from #{Account.default.name}/end
it "should not allow deletes for unmanaged pseudonyms without correct privileges"do@admin= user :account=>Account.default
course_with_student :account=>Account.default
view_context(Account.default,@admin)
assigns[:user]=@student
assigns[:enrollments]=[]
render :partial=>"users/name"expect(response.body).not_to match /Delete from #{Account.default.name}/end
describe "merge_user_link"dolet(:account){Account.default }let(:sally){account_admin_user(account: account)}let(:bob){teacher_in_course(account: account, active_enrollment:true).user }
it "should display when acting user has permission to merge shown user"dopseudonym(bob, account: account)
assigns[:domain_root_account]= account
assigns[:context]= account
assigns[:current_user]= sally
assigns[:user]= bob
assigns[:enrollments]=[]
render partial:"users/name"expect(response).to have_tag("a.merge_user_link")end
it "should not display when acting user lacks permission to merge shown user"dopseudonym(sally, account: account)
assigns[:domain_root_account]= account
assigns[:context]= account
assigns[:current_user]= bob
assigns[:user]= sally
assigns[:enrollments]=[]
render partial:"users/name"expect(response).not_to have_tag("a.merge_user_link")end
it "should not display when non-admin looking at self"do# has permission to merge on self, but wouldn't be able to select any# merge targetspseudonym(bob, account: account)
assigns[:domain_root_account]= account
assigns[:context]=@course
assigns[:current_user]= bob
assigns[:user]= bob
assigns[:enrollments]=[]
render partial:"users/name"expect(response).to have_tag("a.edit_user_link")expect(response).not_to have_tag("a.merge_user_link")endendend

# File: apps/canvas-lms/spec/views/users/admin_merge.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/users/admin_merge"do
it "should only list accounts that the user can merge users in"do
user
@account=Account.create!(:name=>"My Root Account")@account2=@account.sub_accounts.create!(:name=>"Sub-Account")@account.account_users.create!(user:@user)@course1=Course.create!(:account=>Account.default)@course2=Course.create!(:account=>@account2)@course1.enroll_teacher(@user)@course2.enroll_teacher(@user)expect(@user.associated_accounts.map(&:id).sort).to eq [@account.id,@account2.id,Account.default.id].sort
assigns[:current_user]=@user
user
assigns[:user]=@user
render "users/admin_merge"expect(response).not_to be_nil
expect(response.body).to match /My Root Account/expect(response.body).to match /Sub-Account/expect(response.body).not_to match /Default Account/endend

# File: apps/canvas-lms/spec/views/users/new.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/users/new"do
it "should render"do
course_with_student
view_context
assigns[:user]=User.newassigns[:pseudonym]=Pseudonym.newrender"users/new"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/users/registered.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/users/registered"do
it "should render"do
course_with_student
view_context
@user.pseudonyms.create!(:unique_id=>"unique@example.com",:password=>"asdfaa",:password_confirmation=>"asdfaa")
assigns[:cc]=communication_channel(@user)
assigns[:user]=@user
render "users/registered"expect(response).not_to be_nil
endend

# File: apps/canvas-lms/spec/views/users/show.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/users/show"do
it "should render"do
course_with_student
view_context
assigns[:user]=@user
assigns[:courses]=[@course]
assigns[:topics]=[]
assigns[:upcoming_events]=[]
assigns[:enrollments]=[]
assigns[:group_memberships]=[]
assigns[:page_views]=PageView.paginate(:page=>1,:per_page=>20)
render "users/show"expect(response).not_to be_nil
expect(content_for(:right_side)).to include "Message #{@user.name}"# regardless of permissionsendend

# File: apps/canvas-lms/spec/views/users/user_dashboard.html.erb_spec.rb## Copyright (C) 2011 Instructure, Inc.## This file is part of Canvas.## Canvas is free software: you can redistribute it and/or modify it under# the terms of the GNU Affero General Public License as published by the Free# Software Foundation, version 3 of the License.## Canvas is distributed in the hope that it will be useful, but WITHOUT ANY# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more# details.## You should have received a copy of the GNU Affero General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>.#requireFile.expand_path(File.dirname(__FILE__)+'/../../spec_helper')requireFile.expand_path(File.dirname(__FILE__)+'/../views_helper')
describe "/users/user_dashboard"do
it "should render"do
course_with_student
view_context
assigns[:courses]=[@course]
assigns[:enrollments]=[@enrollment]
assigns[:group_memberships]=[]
assigns[:topics]=[]
assigns[:upcoming_events]=[]
assigns[:stream_items]=[]
render "users/user_dashboard"expect(response).not_to be_nil
end
it "should show announcements to users with no enrollments"do
user
view_context
assigns[:courses]=[]
assigns[:enrollments]=[]
assigns[:group_memberships]=[]
assigns[:topics]=[]
assigns[:upcoming_events]=[]
assigns[:stream_items]=[]
assigns[:announcements]=[AccountNotification.create(:message=>'hi',:start_at=>Date.today -1.day,:end_at=>Date.today +2.days,:subject=>"My Global Announcement",:account=>Account.default)]
render "users/user_dashboard"expect(response.body).to match /My Global Announcement/endend