Eliot Sykes

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 -*-
require File.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" do
        assign(: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" do
        assign(:xapian_requests, nil)
        render
        response.should match "The search index is currently offline"
    end

end

def mock_event
    return mock_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/reports/new.erb_spec.rb
# -*- encoding : utf-8 -*-
require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__)

describe 'reports/new.html.erb' do
  let(:info_request) { mock_model(InfoRequest, :url_title => "foo", :report_reasons => ["Weird"]) }
  before :each do
    assign(:info_request, info_request)
  end

  it "should show a form" do
    render
    rendered.should have_selector("form")
  end

  context "request has already been reported" do
    before :each do
      info_request.stub!(:attention_requested).and_return(true)
    end

    it "should not show a form" do
      render
      rendered.should_not have_selector("form")
    end

    it "should say it's already been reported" do
      render
      rendered.should contain("This request has already been reported")
    end
  end
end
# File: apps/alaveteli/spec/views/request/_after_actions.html.erb_spec.rb
# -*- encoding : utf-8 -*-
require File.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_request
    end

    describe 'if the request is old and unclassified' do

        before do
            assign :old_unclassified, true
        end

        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')
            end
        end

        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')
            end
        end

    end

    describe 'if the request is not old and unclassified' do

        before do
            assign :old_unclassified, false
        end

        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')
            end
        end

        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')
            end
        end

    end

    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')
        end
    end


    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')
        end
    end

end
# File: apps/alaveteli/spec/views/request/_describe_state.html.erb_spec.rb
# -*- encoding : utf-8 -*-
require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__)

describe 'when showing the form for describing the state of a request' do

    def expect_radio_button(value)
        do_render
        response.should have_selector('input', :type => 'radio', :value => value)
    end

    def expect_no_radio_button(value)
        do_render
        response.should_not have_selector('input', :type => 'radio', :value => value)
    end

    def 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_request
    end

    describe 'if the user is a regular user (not the request owner)' do

        before do
            assign :is_owning_user, false
        end

        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')
            end

        end

        describe 'if the request is old and unclassified' do

            before do
                assign :old_unclassified, true
            end

            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')
            end
        end

    end

    describe 'if showing the form to the user owning the request' do

        before do
            assign :is_owning_user, true
        end

        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"' do
                expect_radio_button('waiting_response')
            end

            it 'should show a radio button to set the status to "waiting clarification"' do
                expect_radio_button('waiting_clarification')
            end

            it 'should not show a radio button to set the status to "internal_review"' do
                expect_no_radio_button('internal_review')
            end

        end

        describe 'when the user has asked to update the status of the request' do

            before do
                assign :update_status, true
            end

            it 'should show a radio button to set the status to "internal_review"' do
                expect_radio_button('internal_review')
            end

            it 'should show a radio button to set the status to "requires_admin"' do
                expect_radio_button('requires_admin')
            end

            it 'should show a radio button to set the status to "user_withdrawn"' do
                expect_radio_button('user_withdrawn')
            end

        end

        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"' do
                expect_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:')
            end

        end

        describe 'when request is awaiting a description and the user has not asked to update the status' do
        end

        it 'should show a radio button to set the status to "gone postal"' do
            expect_radio_button('gone_postal')
        end

        it 'should show a radio button to set the status to "not held"' do
            expect_radio_button('not_held')
        end

        it 'should show a radio button to set the status to "partially successful"' do
            expect_radio_button('partially_successful')
        end

        it 'should show a radio button to set the status to "successful"' do
            expect_radio_button('successful')
        end

        it 'should show a radio button to set the status to "rejected"' do
            expect_radio_button('rejected')
        end

        it 'should show a radio button to set the status to "error_message"' do
            expect_radio_button('error_message')
        end

        it 'should not show a radio button to set the status to "requires_admin"' do
            expect_no_radio_button('requires_admin')
        end

        it 'should not show a radio button to set the status to "user_withdrawn"' do
            expect_no_radio_button('user_withdrawn')
        end

    end
end
# File: apps/alaveteli/spec/views/request/show.html.erb_spec.rb
# -*- encoding : utf-8 -*-
require File.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')
    end

    def 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, 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

    end

    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")
        end

    end

    describe 'when the user is the request owner' do

        before do
            assign :is_owning_user, true
        end

        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')
                end

            end

            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')
                end
            end
        end

    end
end
# File: apps/alaveteli/spec/views/request_game/play.html.erb_spec.rb
# -*- encoding : utf-8 -*-
require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__)

describe 'request_game/play' 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,
                                                :url_title => 'a_test_request',
                                                :user => @mock_user,
                                                :calculate_status => 'waiting_response',
                                                :date_response_required_by => Date.today,
                                                :prominence => 'normal',
                                                :initial_request_text => 'hi there',
                                                :display_status => 'Awaiting categorisation',
                                                :created_at => Time.now)
        assign :league_table_28_days, []
        assign :league_table_all_time, []
        assign :requests, [@mock_request]
        assign :play_urls, true
    end

    it 'should show the correct url for a request' do
        render
        response.should include("/categorise/request/a_test_request")
    end


end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')

describe "account_authorization_configs/index" do
  let(: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" do
    Setting.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 1
  end

  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 new
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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] = @account
    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#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")
    end
  end

  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] = @account
    end

    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")
    end
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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}/
    end
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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")
    end
  end

  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")
    end
  end

  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")
    end
  end

  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'
      end
    end

    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'
      end
    end
  end

  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'
    end
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')

describe "/assignments/_syllabus_content" do
  context 'js_env CAN_READ' do
    def setup_and_render_context(type, opts={})
      case type
      when :anonymous
        course :active_all => true
      when :non_enrolled_user
        course :active_all => true
        user
      when :enrolled_user
        course_with_student :active_all => true
      end

      if opts[:is_public]
        @course.is_public = true
        @course.save!
      end

      user_session(@user) if @user
      view_context(@course, @user)

      render '/assignments/_syllabus_content'
    end

    before(: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 => true
      expect(@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 => true
      expect(@controller.js_env).to include(:CAN_READ => true)
    end

    example 'enrolled user (non-public course)' do
      setup_and_render_context :enrolled_user
      expect(@controller.js_env).to include(:CAN_READ => true)
    end
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')

describe "/assignments/show" do
  it "should render" do
    course_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()
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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:")
  end
end
# File: apps/canvas-lms/spec/views/communication_channels/confirm.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 File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')

describe "communication_channels/confirm.html.erb" do
  before do
    user
    assigns[:user] = @user
    assigns[:communication_channel] = @cc = @communication_channel = @user.communication_channels.create!(:path => 'johndoe@example.com')
    assigns[:nonce] = @cc.confirmation_code
    assigns[:body_classes] = []
    assigns[:domain_root_account] = assigns[:root_account] = Account.default
    view.stubs(:require_terms?).returns(nil) # since controller-defined helper methods don't get plumbed down here
  end

  shared_examples_for "user registration" do
    it "should only show the registration form if no merge opportunities" do
      assigns[:merge_opportunities] = []
      render
      page = Nokogiri::HTML('<document>' + response.body + '</document>')
      registration_form = page.css('#registration_confirmation_form').first
      expect(registration_form).not_to be_nil
      if @enrollment
        expect(registration_form['style']).to match /display:\s*none/
        expect(page.css('#register.btn').first).not_to be_nil
        expect(page.css('#back.btn').first).to be_nil
      else
        expect(registration_form['style']).to be_blank
        # no "back", "use this account", "new account", etc. buttons
        expect(page.css('a.btn')).to be_empty
      end
    end

    it "should follow the simple path for not logged in" do
      user_with_pseudonym(:active_all => 1)
      assigns[:merge_opportunities] = [[@user, [@user.pseudonym]]]
      render
      page = Nokogiri::HTML('<document>' + response.body + '</document>')
      registration_form = page.css('#registration_confirmation_form').first
      expect(registration_form).not_to be_nil
      expect(registration_form['style']).to match /display:\s*none/
      expect(page.css('input[type="radio"][name="pseudonym_select"]')).to be_empty
      expect(page.css('#register.btn').first).not_to be_nil
      merge_button = page.css('#merge.btn').first
      expect(merge_button).not_to be_nil
      expect(merge_button['href']).to eq login_url(:host => HostUrl.default_host, :confirm => @communication_channel.confirmation_code, :enrollment => @enrollment.try(:uuid), :pseudonym_session => {:unique_id => @pseudonym.unique_id}, :expected_user_id => @pseudonym.user_id)
      expect(page.css('#back.btn').first).not_to be_nil
    end

    it "should follow the simple path for logged in as a matching user" do
      user_with_pseudonym(:active_all => 1)
      @user.communication_channels.create!(:path => 'johndoe@example.com') { |cc| cc.workflow_state = 'active' }
      assigns[:merge_opportunities] = [[@user, [@user.pseudonym]]]
      assigns[:current_user] = @user
      render
      page = Nokogiri::HTML('<document>' + response.body + '</document>')
      registration_form = page.css('#registration_confirmation_form').first
      expect(registration_form).not_to be_nil
      expect(registration_form['style']).to match /display:\s*none/
      expect(page.css('input[type="radio"][name="pseudonym_select"]')).to be_empty
      expect(page.css('#register.btn').first).not_to be_nil
      merge_button = page.css('#merge.btn').first
      expect(merge_button).not_to be_nil
      expect(merge_button.text).to eq 'Yes'
      expect(merge_button['href']).to eq registration_confirmation_path(@communication_channel.confirmation_code, :enrollment => @enrollment.try(:uuid), :confirm => 1)
      expect(page.css('#back.btn').first).not_to be_nil
    end

    it "should follow the simple path for logged in as a non-matching user" do
      user_with_pseudonym(:active_all => 1)
      assigns[:merge_opportunities] = [[@user, [@user.pseudonym]]]
      assigns[:current_user] = @user
      render
      page = Nokogiri::HTML('<document>' + response.body + '</document>')
      registration_form = page.css('#registration_confirmation_form').first
      expect(registration_form).not_to be_nil
      expect(registration_form['style']).to match /display:\s*none/
      expect(page.css('input[type="radio"][name="pseudonym_select"]')).to be_empty
      expect(page.css('#register.btn').first).not_to be_nil
      merge_button = page.css('#merge.btn').first
      expect(merge_button).not_to be_nil
      expect(merge_button['href']).to eq registration_confirmation_path(@communication_channel.confirmation_code, :enrollment => @enrollment.try(:uuid), :confirm => 1)
      expect(merge_button.text).to eq 'Yes, Add Email Address'
      expect(page.css('#back.btn').first).not_to be_nil
    end

    it "should follow the mostly-simple-path for not-logged in with multiple pseudonyms" do
      user_with_pseudonym(:active_all => 1)
      account2 = Account.create!
      assigns[:merge_opportunities] = [[@user, [@user.pseudonym, @user.pseudonyms.create!(:unique_id => 'johndoe', :account => account2)]]]
      render
      page = Nokogiri::HTML('<document>' + response.body + '</document>')
      registration_form = page.css('#registration_confirmation_form').first
      expect(registration_form).not_to be_nil
      expect(registration_form['style']).to match /display:\s*none/
      expect(page.css('input[type="radio"][name="pseudonym_select"]').length).to eq 2
      expect(page.css('#register.btn').first).not_to be_nil
      merge_button = page.css('#merge.btn').first
      expect(merge_button).not_to be_nil
      expect(merge_button['href']).to eq login_url(:host => HostUrl.default_host, :confirm => @communication_channel.confirmation_code, :enrollment => @enrollment.try(:uuid), :pseudonym_session => {:unique_id => @pseudonym.unique_id}, :expected_user_id => @pseudonym.user_id)
      expect(page.css('#back.btn').first).not_to be_nil
    end

    it "should render for multiple merge opportunities" do
      @user1 = user_with_pseudonym(:active_all => 1)
      @user2 = user_with_pseudonym(:active_all => 1, :username => 'janedoe@example.com')
      @user3 = user_with_pseudonym(:active_all => 1, :username => 'freddoe@example.com')
      account2 = Account.create!
      @user3.pseudonyms.create!(:unique_id => 'johndoe', :account => account2)
      @user4 = user_with_pseudonym(:active_all => 1, :username => 'georgedoe@example.com', :account => account2)
      assigns[:merge_opportunities] = [
          [@user1, [@user1.pseudonym]],
          [@user2, [@user2.pseudonym]],
          [@user3, @user3.pseudonyms],
          [@user4, [@user4.pseudonym]]
      ]
      assigns[:current_user] = @user1
      render
      page = Nokogiri::HTML('<document>' + response.body + '</document>')
      registration_form = page.css('#registration_confirmation_form').first
      expect(registration_form).not_to be_nil
      expect(registration_form['style']).to match /display:\s*none/
      expect(page.css('input[type="radio"][name="pseudonym_select"]').length).to eq 6
      expect(page.css('#register.btn')).to be_empty
      merge_button = page.css('#merge.btn').first
      expect(merge_button).not_to be_nil
      expect(merge_button['href']).to eq registration_confirmation_path(@communication_channel.confirmation_code, :enrollment => @enrollment.try(:uuid), :confirm => 1)
      expect(page.css('#back.btn').first).not_to be_nil
    end
  end

  context "invitations" do
    before do
      course(:active_all => true)
      assigns[:course] = @course
      assigns[:enrollment] = @enrollment = @course.enroll_user(@user)
    end

    it "should render transfer enrollment form" do
      assigns[:merge_opportunities] = []
      @user.register
      @pseudonym1 = @user.pseudonyms.create!(:unique_id => 'jt@instructure.com')
      user_with_pseudonym(:active_all => 1)
      assigns[:current_user] = @user

      render
      page = Nokogiri::HTML('<document>' + response.body + '</document>')
      expect(page.css('#registration_confirmation_form').first).to be_nil
      transfer_button = page.css('#transfer.btn').first
      expect(transfer_button).not_to be_nil
      expect(transfer_button['href']).to eq registration_confirmation_path(@communication_channel.confirmation_code, :enrollment => @enrollment.uuid, :transfer_enrollment => 1)
      login_button = page.css('#login.btn').first
      expect(login_button).not_to be_nil
      expect(login_button['href']).to eq login_url(:enrollment => @enrollment.uuid, :pseudonym_session => { :unique_id => 'jt@instructure.com'}, :expected_user_id => @pseudonym1.user_id)
    end

    context "open registration" do
      before do
        @user.update_attribute(:workflow_state, 'creation_pending')
        assigns[:pseudonym] = @user.pseudonyms.build(:account => Account.default)
      end
      include_examples "user registration"
    end
  end

  context "merging" do
    before do
      @user.register
    end

    it "should render to merge with the current user" do
      user_with_pseudonym(:active_all => 1)
      assigns[:current_user] = @user
      assigns[:merge_opportunities] = [[@user, [@pseudonym]]]
      render
      page = Nokogiri::HTML('<document>' + response.body + '</document>')
      expect(page.css('input[type="radio"][name="pseudonym_select"]')).to be_empty
      expect(page.css('#registration_confirmation_form').first).to be_nil
      expect(page.css('#register.btn').first).to be_nil
      merge_button = page.css('#merge.btn').first
      expect(merge_button).not_to be_nil
      expect(merge_button.text).to eq 'Combine'
      expect(merge_button['href']).to eq registration_confirmation_path(@communication_channel.confirmation_code, :confirm => 1, :enrollment => nil)
    end

    it "should render to merge with the current user that doesn't have a pseudonym in the default account" do
      account = Account.create!
      user_with_pseudonym(:active_all => 1, :account => account)
      assigns[:current_user] = @user
      assigns[:merge_opportunities] = [[@user, [@pseudonym]]]
      render
      page = Nokogiri::HTML('<document>' + response.body + '</document>')
      expect(page.css('input[type="radio"][name="pseudonym_select"]')).to be_empty
      expect(page.css('#registration_confirmation_form').first).to be_nil
      expect(page.css('#register.btn').first).to be_nil
      merge_button = page.css('#merge.btn').first
      expect(merge_button).not_to be_nil
      expect(merge_button.text).to eq 'Combine'
      expect(merge_button['href']).to eq registration_confirmation_path(@communication_channel.confirmation_code, :confirm => 1, :enrollment => nil)
    end

    it "should render to merge multiple users" do
      user_with_pseudonym(:active_all => 1)
      @user1 = @user
      @pseudonym1 = @pseudonym
      user_with_pseudonym(:active_all => 1, :username => 'georgedoe@example.com')
      @user2 = @user
      assigns[:merge_opportunities] = [[@user1, [@user1.pseudonym]], [@user2, [@user2.pseudonym]]]
      render
      page = Nokogiri::HTML('<document>' + response.body + '</document>')
      expect(page.css('input[type="radio"][name="pseudonym_select"]').length).to eq 2
      expect(page.css('#registration_confirmation_form').first).to be_nil
      expect(page.css('#register.btn').first).to be_nil
      merge_button = page.css('#merge.btn').first
      expect(merge_button).not_to be_nil
      expect(merge_button.text).to eq 'Continue'
      expect(merge_button['href']).to eq login_url(:host => HostUrl.default_host, :confirm => @communication_channel.confirmation_code, :pseudonym_session => {:unique_id => @pseudonym1.unique_id}, :expected_user_id => @pseudonym1.user_id)
    end
  end

  context "self-registration" do
    before do
      assigns[:pseudonym] = @user.pseudonyms.create!(:unique_id => 'johndoe@example.com')
    end

    include_examples "user registration"
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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" do
    course_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")
  end
end
# File: apps/canvas-lms/spec/views/context/_roster_right_side.html.erb_spec.rb
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')

describe "/context/_roster_right_side" do
  it "should render with an account as context" do
    view_context(Account.default)
    render :partial => "context/roster_right_side"
    expect(response).not_to be_nil
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')

describe "context/undelete_index.html.erb" do
  before do
    course_with_teacher(:active_all => true)
    assigns[:context] = @course
  end

  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}/
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')

describe "/context_modules/index" do
  before :each do
    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 1
  end

  it "should show unpublished content_tags" do
    course_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 1
  end

  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 0
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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']
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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" do
    before(: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}/
    end
  end
end

# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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.name
  end
end
# File: apps/canvas-lms/spec/views/courses/settings.html.erb_spec.rb
#
# Copyright (C) 2011-12 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 File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')

describe "courses/settings.html.erb" do
  before do
    course_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 "sis_source_id edit box" do
    it "should not show to teacher" do
      view_context(@course, @user)
      assigns[:current_user] = @user
      render
      expect(response).to have_tag("span#course_sis_source_id", @course.sis_source_id)
      expect(response).not_to have_tag("input#course_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_sis_source_id")
    end

    it "should not show to non-sis admin" do
      role = custom_account_role('NoSissy', :account => @course.root_account)
      admin = account_admin_user_with_role_changes(:account => @course.root_account, :role_changes => {'manage_sis' => false}, :role => role)
      view_context(@course, admin)
      assigns[:current_user] = admin
      render
      expect(response).not_to have_tag("input#course_sis_source_id")
    end

    it "should show grade export when enabled" do
      admin = account_admin_user(:account => @course.root_account)
      @course.expects(:allows_grade_publishing_by).with(admin).returns(true)
      view_context(@course, admin)
      assigns[:current_user] = admin
      render
      expect(response.body).to match /<a href="#tab-grade-publishing" id="tab-grade-publishing-link">/
      expect(response.body).to match /<div id="tab-grade-publishing">/
    end

    it "should not show grade export when disabled" do
      admin = account_admin_user(:account => @course.root_account)
      @course.expects(:allows_grade_publishing_by).with(admin).returns(false)
      view_context(@course, admin)
      assigns[:current_user] = admin
      render
      expect(response.body).not_to match /<a href="#tab-grade-publishing" id="tab-grade-publishing-link">/
      expect(response.body).not_to match /<div id="tab-grade-publishing">/
    end
  end

  describe "quota box" do
    context "as account admin" do
      before do
        admin = account_admin_user
        view_context(@course, admin)
        assigns[:current_user] = admin
      end

      it "should show quota input box" do
        render
        expect(response).to have_tag "input#course_storage_quota_mb"
      end
    end

    context "as teacher" do
      before do
        view_context(@course, @teacher)
        assigns[:current_user] = @teacher
        @user = @teacher
      end

      it "should not show quota input box" do
        render
        expect(response).not_to have_tag "input#course_storage_quota_mb"
      end
    end
  end

  context "account_id selection" do
    it "should let sub-account admins see other accounts within their sub-account as options" do
      root_account = Account.create!(:name => 'root')
      subaccount = account_model(:parent_account => root_account)
      other_subaccount = account_model(:parent_account => root_account) # should not include
      sub_subaccount1 = account_model(:parent_account => subaccount)
      sub_subaccount2 = account_model(:parent_account => subaccount)

      @course.account = sub_subaccount1
      @course.save!

      @user = account_admin_user(:account => subaccount, :active_user => true)
      expect(root_account.grants_right?(@user, :manage_courses)).to be_falsey
      view_context(@course, @user)

      render
      doc = Nokogiri::HTML(response.body)
      select = doc.at_css("select#course_account_id")
      expect(select).not_to be_nil
      #select.children.count.should == 3

      option_ids = select.search("option").map{|c| c.attributes["value"].value.to_i rescue c.to_s}
      expect(option_ids.sort).to eq [subaccount.id, sub_subaccount1.id, sub_subaccount2.id].sort
    end

    it "should let site admins see all accounts within their root account as options" do
      root_account = Account.create!(:name => 'root')
      subaccount = account_model(:parent_account => root_account)
      other_subaccount = account_model(:parent_account => root_account)
      sub_subaccount1 = account_model(:parent_account => subaccount)
      sub_subaccount2 = account_model(:parent_account => subaccount)

      @course.account = sub_subaccount1
      @course.save!

      @user = site_admin_user
      view_context(@course, @user)

      render
      doc = Nokogiri::HTML(response.body)
      select = doc.at_css("select#course_account_id")
      expect(select).not_to be_nil
      all_accounts = [root_account] + root_account.all_accounts

      option_ids = select.search("option").map{|c| c.attributes["value"].value.to_i}
      expect(option_ids.sort).to eq all_accounts.map(&:id).sort
    end
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')

describe "courses/_settings_sidebar.html.erb" do
  before do
    course_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/)
    end
  end

  describe "Reset course content" do
    it "should not display the dialog contents under the button" do
      view_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;'
    end
  end

  describe "course settings sub navigation external tools" do
    def create_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 do
      view_context(@course, @user)
      assigns[:current_user] = @user
    end

    it "should display all configured tools" do
      num_tools = 3
      (1..num_tools).each do |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")
    end
  end

end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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}
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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" do
    assignment_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")
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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)
    end
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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")
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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")
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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" do
    course_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}}
    )
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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/
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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 0
  end

  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" do
    course_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./)
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')

describe "/gradebooks/gradebook2" do

  def test_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/
    else
      expect(response.body).not_to match /Publish grades to SIS/
    end
  end

  it "should enable grade publishing when appropriate" do
    test_grade_publishing(true, true)
  end

  it "should disable grade publishing when the course disallows it" do
    test_grade_publishing(false, true)
  end

  it "should disable grade publishing when permissions disallow it" do
    test_grade_publishing(true, false)
  end

  describe "uploading scores" do
    before :each do
      course_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/
    end
  end

end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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\""
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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 => @user
    expect(response).not_to be_nil
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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" do
    view_context(Account.default)

    render "groups/context_groups"
    expect(response).not_to be_nil
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe "layouts/application" do
  it "should render" do
    assigns[:domain_root_account] = Account.default
    render "layouts/application"
  end
end
# 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'" do
    Account.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" do
    let(: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)
    end
  end
end
# File: apps/canvas-lms/spec/views/plugins/show.html.erb_spec.rb
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')

describe "plugins/show" do
  it "renders without exploding" do
    plugin = stub(
      id: 'some_plugin',
      name: "Some Plugin",
      settings_partial: "settings_header"
    )
    plugin_setting = PluginSetting.new()

    assigns[:plugin] = plugin
    assigns[:plugin_setting] = plugin_setting
    view.stubs(:plugin_path).returns("/some/path")
    view.stubs(:params).returns({id: 'some_plugin'})
    render 'plugins/show'
    expect(response.body).to match("Return to plugins list")
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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/
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')

describe "/profile/profile" do
  it "should render" do
    course_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" do
    account_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" do
    course_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;'
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.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.new
    render :partial => "quizzes/quizzes/multi_answer", :object => answer, :locals => {:question => question, :question_type => question_type, :user_answer => nil}
    expect(response).not_to be_nil
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.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"
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.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 => @quiz

    expect(response).not_to be_nil
    expect(response.body).to match /Instructor is working on grades/
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.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.new
    answer.id = 5
    answer.weight = 100
    question_type = OpenObject.new
    render :partial => "quizzes/quizzes/single_answer", :object => answer, :locals => {:question_type => question_type, :user_answer => nil}
    expect(response).not_to be_nil
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../../views_helper')

describe "/quizzes/quizzes/history" do
  before do
    course_with_student
    view_context
    assigns[:user] = @user
  end

  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/
    end
  end

  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/
    end
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../../views_helper')

describe "/quizzes/quizzes/new" do
  def course_quiz(active=false)
    @quiz = @course.quizzes.create
    @quiz.workflow_state = "available" if active
    @quiz.save!
    @quiz
  end

  def 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 :each do
      course_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" do
      Quizzes::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")
    end
  end

end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.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" do
    course_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"
    true
  end

  it "doesn't warn students if quiz is published" do
    course_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" do
    course_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" do
    course_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"
  end

end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.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|
      next if row.name != 'tr'
      row = row.children.find_all{|col| col.name == 'td'}
      next if row.size != 2
      kv[row[0].text] = row[1].text
    end
    expect(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|
      next if row.name != 'tr'
      row = row.children.find_all{|col| col.name == 'td'}
      next if row.size != 2
      kv[row[0].text] = row[1].text
    end
    expect(kv).to eq({
      "Low Score:" => "_",
      "Average Time:" => "less than a minute",
      "Average Incorrect:" => "_",
      "Standard Deviation:" => "_",
      "High Score:" => "_",
      "Mean Score:" => "_",
      "Average Correct:" => "_"
    })
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../../views_helper')

describe "/quizzes/quizzes/submission_versions" do
  it "should render" do
    course_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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')

describe "sections/show.html.erb" do
  describe "sis_source_id edit box" do
    before do
      course_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" do
      view_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)
    end
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# File: apps/canvas-lms/spec/views/shared/_auth_type_icon.html.erb_spec.rb
require_relative '../../spec_helper'
require_relative '../views_helper'

describe "/shared/_flash_notices" do
  def local_options(overrides={})
    {
      with_login_text: true,
      auth_type: 'facebook',
      sr_message: nil
    }.merge(overrides)
  end

  it "puts login text with the button if flagged" do
    render partial: "shared/auth_type_icon", locals: local_options(with_login_text: true)
    expect(rendered).to match("Login with <span class=\"ic-Login_sso-button_title")
  end

  it "just uses the icon if flagged to not use login text" do
    render partial: "shared/auth_type_icon", locals: local_options(with_login_text: false)
    expect(rendered).to_not match("Login with <span class=\"ic-Login_sso-button_title")
  end

  it "renders a screenreader message if provided" do
    render partial: "shared/auth_type_icon", locals: local_options(sr_message: "SR_ONLY")
    expect(rendered).to match("<span class=\"screenreader-only\">SR_ONLY")
  end

  it "omits screenreader span if no message provided" do
    render partial: "shared/auth_type_icon", locals: local_options(sr_message: nil)
    expect(rendered).to_not match("<span class=\"screenreader-only\">")
  end

  it "uses the button icon based on auth type" do
    render partial: "shared/auth_type_icon", locals: local_options(auth_type: 'twitter')
    expect(rendered).to match(/sso-twitter(-)?\w*\.svg/)
  end

end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')

describe "/shared/_identity" do
  it "should render" do
    Setting.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" do
    Setting.set('show_feedback_link', 'true')
    course_with_student
    view_context
    assigns.delete(:current_user)
    render :partial => "shared/identity"
    expect(@controller.response).to be_success
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end

# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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_empty
    expect(page.css(%Q{#quizs_select .module_item_select option[value="new"]})).to be_empty
    expect(page.css(%Q{#assignments_select .module_item_select option[value="new"]})).to be_empty
  end

  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_empty
  end

  it "should create new topics in unpublished state if draft state is enabled" do
    course_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_nil
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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" do
    Account.default.login_handle_name = 'Login'
    Account.default.save!
    assigns[:context] = Account.default
    render :partial => "shared/user_lists"
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../../views_helper')

describe "/shared/errors/400_message" do
  it "should render" do
    course_with_student
    view_context
    begin
      nil.bad_method
    rescue => e
      assigns[:exception] = e
    end
    ActionController::TestResponse.any_instance.stubs(:status).returns(400)
    render "shared/errors/400_message"
    expect(response).not_to be_nil
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../../views_helper')

describe "/shared/errors/404_message" do
  it "should render" do
    course_with_student
    view_context
    begin
      nil.bad_method
    rescue => e
      assigns[:exception] = e
    end
    render "shared/errors/404_message", :locals => {:exception => assigns[:exception], :status => ""}
    expect(response).not_to be_nil
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../../views_helper')

describe "/shared/errors/500_message" do
  it "should render" do
    course_with_student
    view_context
    begin
      nil.bad_method
    rescue => e
      assigns[:exception] = e
    end
    ActionController::TestResponse.any_instance.stubs(:status).returns(500)
    render "shared/errors/500_message"
    expect(response).not_to be_nil
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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/
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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 '#'
  end
end
# File: apps/canvas-lms/spec/views/users/_logins.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 File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')

describe "users/_logins.html.erb" do
  describe "sis_source_id edit box" do
    before do
      user_with_pseudonym
      @account = Account.default
      @student = @user
      @pseudo = @user.pseudonyms.first
      @pseudo.sis_user_id = "why_is_this_one_user_id_lame"
      @pseudo.save
      @pseudo2 = @user.pseudonyms.create!(:unique_id => 'someone@somewhere.com') { |p| p.sis_user_id = 'more' }
      assigns[:context] = @account
      assigns[:context_account] = @account
      assigns[:account] = @account
      assigns[:root_account] = @account
      assigns[:user] = @student
      assigns[:current_enrollments] = []
      assigns[:completed_enrollments] = []
      assigns[:student_enrollments] = []
      assigns[:pending_enrollments] = []
      assigns[:enrollments] = []
      assigns[:courses] = []
      assigns[:page_views] = []
      assigns[:group_memberships] = []
      assigns[:context_groups] = []
      assigns[:contexts] = []
    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("span#sis_user_id_#{@pseudo.id}", @pseudo.sis_user_id)
      expect(response).to have_tag("div.can_edit_sis_user_id", 'true')
      page = Nokogiri('<document>' + response.body + '</document>')
      expect(page.css(".login .delete_pseudonym_link").first['style']).to eq ''
    end

    it "should not show to non-sis admin" do
      admin = account_admin_user_with_role_changes(:role_changes => {'manage_sis' => false}, :account => @account)
      view_context(@account, admin)
      assigns[:current_user] = admin
      render
      expect(response).to have_tag("span#sis_user_id_#{@pseudo.id}", @pseudo.sis_user_id)
      expect(response).to have_tag("div.can_edit_sis_user_id", 'false')
      page = Nokogiri('<document>' + response.body + '</document>')
      expect(page.css(".login .delete_pseudonym_link").first['style']).to eq 'display: none;'
    end
  end

  describe "add_pseudonym_link" do
    let(:account) { Account.default }
    let(:sally) { account_admin_user(account: account) }
    let(:bob) { student_in_course(account: account).user }

    it "should display when user has permission to create pseudonym" do
      assigns[:domain_root_account] = account
      assigns[:current_user] = sally
      assigns[:user] = bob
      render
      expect(response).to have_tag("a.add_pseudonym_link")
    end

    it "should not display when user lacks permission to create pseudonym" do
      assigns[:domain_root_account] = account
      assigns[:current_user] = bob
      assigns[:user] = sally
      render
      expect(response).not_to have_tag("a.add_pseudonym_link")
    end
  end

  describe "reset_mfa_link" do
    let(:account) { Account.default }
    let(:sally) { account_admin_user(account: account) }
    let(:bob) { student_in_course(account: account).user }

    it "should display when user has permission to reset MFA" do
      pseudonym(bob, account: account)
      bob.otp_secret_key = 'secret'

      assigns[:domain_root_account] = account
      assigns[:current_user] = sally
      assigns[:user] = bob
      render
      expect(response).to have_tag("a.reset_mfa_link")
    end

    it "should not display when user lacks permission to reset MFA" do
      pseudonym(sally, account: account)
      sally.otp_secret_key = 'secret'

      assigns[:domain_root_account] = account
      assigns[:current_user] = bob
      assigns[:user] = sally
      render
      expect(response).not_to have_tag("a.reset_mfa_link")
    end
  end

  describe "add_holder" do
    let(:account) { Account.default }
    let(:sally) { account_admin_user(account: account) }
    let(:bob) { student_in_course(account: account).user }

    it "should display when user can only reset MFA" do
      pseudonym(bob, account: account)
      bob.otp_secret_key = 'secret'

      assigns[:domain_root_account] = account
      assigns[:current_user] = bob
      assigns[:user] = bob
      render
      expect(response).to have_tag(".add_holder")
    end

    it "should display when user can only add pseudonym" do
      pseudonym(sally, account: account)
      sally.otp_secret_key = 'secret'
      account.settings[:mfa_settings] = :required
      account.save!

      assigns[:domain_root_account] = account
      assigns[:current_user] = sally
      assigns[:user] = sally
      render
      expect(response).to have_tag(".add_holder")
    end

    it "should not display when user lacks permission to do either" do
      pseudonym(bob, account: account)
      bob.otp_secret_key = 'secret'
      account.settings[:mfa_settings] = :required
      account.save!

      assigns[:domain_root_account] = Account.default
      assigns[:current_user] = bob
      assigns[:user] = bob
      render
      expect(response).not_to have_tag(".add_holder")
    end
  end

  context "authentication providers" do
    it "doesn't show an icon for SAML" do
      account_with_saml
      user_with_pseudonym(active_all: 1)
      ap = @account.authentication_providers.first
      @pseudonym.authentication_provider = ap
      @pseudonym.save!

      assigns[:domain_root_account] = @account
      assigns[:current_user] = @user
      assigns[:user] = @user
      render

      doc = Nokogiri::HTML(response)
      expect(doc.at_css('.screenreader-only')).to be_nil
    end
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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" do
    let(: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" do
      pseudonym(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" do
      pseudonym(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 targets
      pseudonym(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")
    end
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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/
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')

describe "/users/new" do
  it "should render" do
    course_with_student
    view_context
    assigns[:user] = User.new
    assigns[:pseudonym] = Pseudonym.new

    render "users/new"
    expect(response).not_to be_nil
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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 permissions
  end
end
# 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/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.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/
  end
end
# File: apps/discourse/spec/views/omniauth_callbacks/complete.html.erb_spec.rb
require "spec_helper"

require "auth/authenticator"
require_dependency "auth/result"

describe "users/omniauth_callbacks/complete.html.erb" do

  let :rendered_data do
    returned = JSON.parse(rendered.match(/window.opener.Discourse.authenticationComplete\((.*)\)/)[1])
  end

  it "renders auth info" do
    result = Auth::Result.new
    result.user = User.new

    assign(:auth_result, result)

    render

    expect(rendered_data["authenticated"]).to eq(false)
    expect(rendered_data["awaiting_activation"]).to eq(false)
    expect(rendered_data["awaiting_approval"]).to eq(false)
  end

  it "renders cas data " do
    result = Auth::Result.new

    result.email = "xxx@xxx.com"
    result.authenticator_name = "CAS"

    assign(:auth_result, result)

    render

    expect(rendered_data["email"]).to eq(result.email)
    # TODO this is a bit weird, the upcasing is confusing,
    #  clean it up throughout
    expect(rendered_data["auth_provider"]).to eq("Cas")
  end

end
# File: apps/discourse/spec/views/omniauth_callbacks/failure.html.erb_spec.rb
require "spec_helper"

describe "users/omniauth_callbacks/failure.html.erb" do

    it "renders the failure page" do
        flash[:error] = I18n.t("login.omniauth_error", strategy: 'test')
        render

        expect(rendered.match(I18n.t("login.omniauth_error", strategy: 'test'))).not_to eq(nil)
    end

end
# File: apps/enki/spec/views/admin/comments/index.html_spec.rb
require File.dirname(__FILE__) + '/../../../spec_helper'

describe "/admin/comments/index.html" do
  after(:each) do
    rendered.should be_valid_html5_fragment
  end

  it 'should render' do
    comments = [mock_model(Comment,
      :author     => 'Don Alias',
      :body       => 'Hello I am a post',
      :created_at => Time.now,
      :post_title => 'A Post',
      :post => mock_model(Post,
        :slug         => 'a-post',
        :published_at => Time.now
      )
    )]
    comments.stub(:total_pages).and_return(1)
    assign :comments, comments
    render :template => '/admin/comments/index', :formats => [:html]
  end
end
# File: apps/enki/spec/views/admin/comments/show.html_spec.rb
require File.dirname(__FILE__) + '/../../../spec_helper'

describe "/admin/comments/show.html" do
  after(:each) do
    rendered.should be_valid_html5_fragment
  end

  it 'should render' do
    assign :comment, Comment.new(
      :author                  => 'Don Alias',
      :author_url              => 'http://enkiblog.com',
      :author_email            => 'donalias@enkiblog.com',
      :body                    => 'Hello I am a post',
      :created_at              => Time.now
    )
    allow_message_expectations_on_nil
    assigns[:comment].stub(:post).and_return(mock_model(Post,
      :title        => 'A post',
      :slug         => 'a-post',
      :published_at => Time.now
    ))
    render :template => '/admin/comments/show', :formats => [:html]
  end
end
# File: apps/enki/spec/views/admin/dashboard/show.html_spec.rb
require File.dirname(__FILE__) + '/../../../spec_helper'

describe "/admin/dashboard/show.html" do
  before(:each) do
    view.stub(:enki_config).and_return(Enki::Config.default)
  end

  after(:each) do
    rendered.should be_valid_html5_fragment
  end

  it 'should render' do
    assign :posts, [mock_model(Post,
      :title             => 'A Post',
      :published_at      => Time.now,
      :slug              => 'a-post',
      :approved_comments => []
    )]
    assign :comment_activity, [double("comment-activity-1",
      :post                => mock_model(Post,
        :published_at      => Time.now,
        :published?        => true,
        :title             => "A Post",
        :slug              => 'a-post',
        :approved_comments => []
      ),
      :comments            => [mock_model(Comment, :author => 'Don', :body_html => 'Hello')],
      :most_recent_comment => mock_model(Comment, :created_at => Time.now, :author => 'Don')
    )]
    assign :stats, Struct.new(:post_count, :comment_count, :tag_count).new(3,2,1)
    render :template => '/admin/dashboard/show', :formats => [:html]
  end
end
# File: apps/enki/spec/views/admin/pages/index.html_spec.rb
require File.dirname(__FILE__) + '/../../../spec_helper'

describe "/admin/pages/index.html" do
  after(:each) do
    rendered.should be_valid_html5_fragment
  end

  it 'should render' do
    pages = [mock_model(Page,
      :title      => 'A page',
      :body       => 'Hello I am a page',
      :slug       => 'a-page',
      :created_at => Time.now
    )]
    pages.stub(:total_pages).and_return(1)
    assign :pages, pages
    render :template => '/admin/pages/index', :formats => [:html]
  end
end
# File: apps/enki/spec/views/admin/pages/new.html_spec.rb
require File.dirname(__FILE__) + '/../../../spec_helper'

describe "/admin/pages/new.html" do
  after(:each) do
    rendered.should be_valid_html5_fragment
  end

  it 'should render' do
    assign :page, Page.new
    render :template => '/admin/pages/new', :formats => [:html]
  end
end
# File: apps/enki/spec/views/admin/pages/show.html_spec.rb
require File.dirname(__FILE__) + '/../../../spec_helper'

describe "/admin/pages/show.html" do
  after(:each) do
    rendered.should be_valid_html5_fragment
  end

  it 'should render' do
    assign :page, Page.new(
      :title      => 'A Post',
      :created_at => Time.now,
      :slug       => 'a-page'
    )
    render :template => '/admin/pages/show', :formats => [:html]
  end
end
# File: apps/enki/spec/views/admin/posts/index.html_spec.rb
require File.dirname(__FILE__) + '/../../../spec_helper'

describe "/admin/posts/index.html" do
  after(:each) do
    rendered.should be_valid_html5_fragment
  end

  it 'should render' do
    posts = [mock_model(Post,
      :published_at      => Time.now,
      :title             => 'A post',
      :body              => 'Hello I am a post',
      :slug              => 'a-post',
      :approved_comments => []
    )]
    posts.stub(:total_pages).and_return(1)
    assign :posts, posts
    render :template => '/admin/posts/index', :formats => [:html]
  end
end
# File: apps/enki/spec/views/admin/posts/new.html_spec.rb
require File.dirname(__FILE__) + '/../../../spec_helper'

describe "/admin/posts/new.html" do
  after(:each) do
    rendered.should be_valid_html5_fragment
  end

  it 'should render' do
    assign :post, Post.new
    render :template => '/admin/posts/new', :formats => [:html]
  end
end
# File: apps/enki/spec/views/admin/posts/show.html_spec.rb
require File.dirname(__FILE__) + '/../../../spec_helper'

describe "/admin/posts/show.html" do
  after(:each) do
    rendered.should be_valid_html5_fragment
  end

  it 'should render' do
    assign :post, Post.new(
      :title        => 'A Post',
      :published_at => Time.now,
      :slug         => 'a-post'
    )
    render :template => '/admin/posts/show', :formats => [:html]
  end
end
# File: apps/enki/spec/views/admin/sessions/new.html_spec.rb
require File.dirname(__FILE__) + '/../../../spec_helper'

describe "/admin/sessions/new.html" do
  after(:each) do
    rendered.should be_valid_html5_fragment
  end

  it "renders" do
    view.stub(:enki_config).and_return(Enki::Config.default)
    view.stub(:allow_login_bypass?).and_return(true)
    view.stub(:auth_path).and_return('/auth/omniauth_path')
    render :template => '/admin/sessions/new', :formats => [:html]
  end
end
# File: apps/enki/spec/views/admin/undo_items/index.html_spec.rb
require File.dirname(__FILE__) + '/../../../spec_helper'

describe "/admin/undo_items/index.html" do
  after(:each) do
    rendered.should be_valid_html5_fragment
  end

  it 'should render' do
    assign :undo_items, [mock_model(UndoItem,
      :created_at  => Time.now,
      :description => 'Deleted a comment'
    )]
    render :template => '/admin/undo_items/index', :formats => [:html]
  end
end
# File: apps/enki/spec/views/archives/index.html_spec.rb
require File.dirname(__FILE__) + '/../../spec_helper'

describe "/archives/index.html" do
  def tag(name)
    mock_model(Tag, :name => name)
  end

  before(:each) do
    view.stub(:enki_config).and_return(Enki::Config.default)

    month = Struct.new(:date, :posts)
    assign :months, [
      month.new(1.month.ago.utc.beginning_of_month, [
        mock_model(Post, :title => 'Post A', :published_at => 3.weeks.ago.utc, :slug => 'post-a', :tags => [tag("Code")])
      ]),
      month.new(2.months.ago.utc.beginning_of_month, [
        mock_model(Post, :title => 'Post B', :published_at => 6.weeks.ago.utc, :slug => 'post-b', :tags => [tag("Code"), tag("Ruby")]),
        mock_model(Post, :title => 'Post C', :published_at => 7.weeks.ago.utc, :slug => 'post-c', :tags => [])
      ])
    ]
  end

  after(:each) do
    rendered.should be_valid_html5_fragment
  end

  it 'renders posts grouped by month' do
    render :template => "/archives/index", :formats => [:html]
  end
end
# File: apps/enki/spec/views/layouts/admin.html_spec.rb
require File.dirname(__FILE__) + '/../../spec_helper'

describe "/layouts/admin.html" do
  it 'renders' do
    view.stub(:enki_config).and_return(Enki::Config.default)
    render :template => '/layouts/admin', :formats => [:html]
  end
end
# File: apps/enki/spec/views/layouts/application.html_spec.rb
require File.dirname(__FILE__) + '/../../spec_helper'

describe "/layouts/application.html" do
  before(:each) do
    view.stub(:enki_config).and_return(Enki::Config.default)

    mock_tag = mock_model(Tag,
      :name     => 'code',
      :taggings => [mock_model(Tagging)]
    )
    Tag.stub(:find).and_return([mock_tag])

    mock_page = mock_model(Page,
      :title     => 'about',
      :slug     => 'about'
    )
    Page.stub(:find).and_return([mock_page])
  end

  it 'renders' do
    render :template => '/layouts/application', :formats => [:html]
  end
end
# File: apps/enki/spec/views/layouts/login.html_spec.rb
require File.dirname(__FILE__) + '/../../spec_helper'

describe "/layouts/login.html" do
  it 'renders' do
    view.stub(:enki_config).and_return(Enki::Config.default)
    render :template => '/layouts/login', :formats => [:html]
  end
end
# File: apps/enki/spec/views/pages/show.html_spec.rb
require File.dirname(__FILE__) + '/../../spec_helper'

describe "/pages/show.html" do
  include UrlHelper

  before(:each) do
    view.stub(:enki_config).and_return(Enki::Config.default)

    @page = mock_model(Page,
      :title             => "A page",
      :body_html         => "Page content!",
      :slug              => 'a-page'
    )
    assign :page, @page
  end

  after(:each) do
    rendered.should be_valid_html5_fragment
  end

  it "should render a page" do
    render :template => "/pages/show", :formats => [:html]
  end
end
# File: apps/enki/spec/views/posts/index.atom.builder_spec.rb
require File.dirname(__FILE__) + '/../../spec_helper'

describe "/posts/index.atom.builder" do
  before(:each) do
    view.stub(:enki_config).and_return(Enki::Config.default)

    mock_tag = mock_model(Tag,
      :name => 'code'
    )

    mock_post = mock_model(Post,
      :title             => "A post",
      :body_html         => "Posts contents!",
      :published_at      => 1.year.ago,
      :edited_at         => 1.year.ago,
      :slug              => 'a-post',
      :approved_comments => [mock_model(Comment)],
      :tags              => [mock_tag]
    )

    assign :posts, [mock_post, mock_post]
  end

  it "should render list of posts" do
    render :template => "/posts/index", :formats => [:atom], :handler => [:builder]
  end

  it "should render list of posts with a tag" do
    assigns[:tag] = 'code'
    render :template => "/posts/index", :formats => [:atom], :handler => [:builder]
  end
end
# File: apps/enki/spec/views/posts/index.html_spec.rb
require File.dirname(__FILE__) + '/../../spec_helper'

describe "/posts/index.html" do
  before(:each) do
    view.stub(:enki_config).and_return(Enki::Config.default)

    mock_tag = mock_model(Tag,
      :name => 'code'
    )

    mock_post = mock_model(Post,
      :title             => "A post",
      :body_html         => "Posts contents!",
      :published_at      => 1.year.ago,
      :published?        => true,
      :slug              => 'a-post',
      :approved_comments => [mock_model(Comment)],
      :tags              => [mock_tag]
    )

    assign :posts, [mock_post, mock_post]
  end

  after(:each) do
    rendered.should be_valid_html5_fragment
  end

  it "should render list of posts" do
    render :template => "/posts/index", :formats => [:html]
  end

  it "should render list of posts with a tag" do
    assigns[:tag] = 'code'
    render :template => "/posts/index", :formats => [:html]
  end
end
# File: apps/enki/spec/views/posts/show.html_spec.rb
require File.dirname(_