require 'spec_helper'

describe "Content creation" do 
	let(:customer) { create :customer }
	let(:subtrade) { create :subtrade }

	trade { page }

	before do
		login_as_user customer 
		visit customer_contents_path
		click_link 'Create New Content'
	end

	describe "invalid file upload" do
		before do 
			find(:xpath, "//input[@id='hidden_id']").set subtrade.id
			attach_file "file_path", '/home/charizard/loading.gif'
			click_button "submit"
		end

		it "should be able to upload", js: true do
			page.status_code.should == 200
		end
		it "should validate content_type" do
			should have_content "Document content type is invalid"
		end
	end

	describe "valid file upload" do
		before do 
			find(:xpath, "//input[@id='hidden_id']").set subtrade.id
			attach_file "file_path", '/home/charizard/Downloads/SOA-341483-072013.pdf'
			click_button "submit"
		end

		it "should be able to upload", js: true do
			page.status_code.should == 200
		end
		it "should validate content_type" do
			should have_content "Uploaded your document. Pending approval by admin."
		end
	end

	describe "private file upload" do
		let(:customer1) { create :customer }
		let(:private_content) { create :content, user: customer, private_content: true }
		before do 
			login_as_user customer1
			click_link "Get the Scoop"
			click_link "Contents"
		end

		it{ should_not have_content private_content.document_file_name }
	end

end