require 'spec_helper'

describe "Customer visiting fixxpert page" do
	let(:customer) {create :customer}
	let(:fixxpert) {create :fixxpert}
	let(:subtrade) {create :subtrade}
	let(:content) {create :content, user: fixxpert}
	let(:expert_session) {create :expert_session, fixxpert: fixxpert, customer: customer}

	before do
		fixxpert.subtrades<< subtrade
		login_as_user customer
		visit customer_fixxpert_path(fixxpert)
	end

	trade{page}

	it{ should have_content "Contents" }
	it "should not be able to see contents if session is not confirmed and content not approved" do
		should_not have_content content.document_file_name
	end

	describe "should not be able to see contents if session is confirmed and content approved" do
		before do
			expert_session.status = "c"
			expert_session.save
			content.approved = true
			content.save

			visit customer_fixxpert_path(fixxpert)
		end
		it{ should_not have_content content.document_file_name }
	end

	describe "should not be able to see contents if session is not confirmed and content approved" do
		before do
			content.approved = true
			content.save

			visit customer_fixxpert_path(fixxpert)
		end
		it{ should_not have_content content.document_file_name }
	end

	describe "should not be able to see contents if session is confirmed and content not approved" do
		before do
			expert_session.status = "c"
			expert_session.save

			visit customer_fixxpert_path(fixxpert)
		end
		it{ should_not have_content content.document_file_name }
	end
end