<commit_before>#encoding:utf-8
require 'spec_helper'

describe ProjectsController do
  before{ Notification.unstub(:create_notification) }
  before{ Notification.unstub(:create_notification_once) }
  before{ controller.stub(:current_user).and_return(current_user) }
  before{ ::Configuration[:base_url] = 'http://catarse.me' }
  render_views
  subject{ response }
  let(:project){ create(:project, state: 'draft') }
  let(:current_user){ nil }

  describe "POST create" do
    let(:project){ build(:project) }
    before do
      post :create, { locale: :pt, project: project.attributes }
    end

    context "when no user is logged in" do
      it{ should redirect_to new_user_session_path }
    end

    context "when user is logged in" do
      let(:current_user){ create(:user) }
      it{ should redirect_to success_project_path(project) }
    end
  end

  describe 'GET success' do
    let(:project){ create(:project) }

    context 'when has successful_created session' do
      before do
        session[:successful_created] = project.id
        get :success, id: project
      end

      it { expect(response).to be_success }

      it 'should set successful_created session as false' do
        expect(session[:successful_created]).to be_false
      end
    end

    context 'when does not have successful_created session' do
      before do
        session[:sucessful_created] = false
        get :success, id: project
      end

      it { expect(response).to redirect_to project_path(project) }
    end
  end

  describe "DELETE destroy" do
    before do
      delete :destroy, id: project, locale: :pt
    end

    context "when user is a guest" do
      it { Project.all.include?(project).should be_true }
    end

    context "when user is a project owner" do
      let(:current_user){ project.user }
      it { Project.all.include?(project).should be_true }
    end

    context "when user is a registered user" do
      let(:current_user){ create(:user, admin: false) }
      it { Project.all.include?(project).should be_true }
    end

    context "when user is an admin" do
      let(:current_user){ create(:user, admin: true) }
      it { Project.all.include?(project).should be_false }
    end
  end

  describe 'GET index' do
    before do
      controller.stub(:last_tweets).and_return([])
      get :index, locale: :pt
    end
    it { should be_success }
  end
<commit_msg>Add specs for basic auth on staging and users without email<commit_after>#encoding:utf-8
require 'spec_helper'

describe ProjectsController do
  before{ Notification.unstub(:create_notification) }
  before{ Notification.unstub(:create_notification_once) }
  before{ controller.stub(:current_user).and_return(current_user) }
  before{ ::Configuration[:base_url] = 'http://catarse.me' }
  render_views
  subject{ response }
  let(:project){ create(:project, state: 'draft') }
  let(:current_user){ nil }

  describe "POST create" do
    let(:project){ build(:project) }
    before do
      post :create, { locale: :pt, project: project.attributes }
    end

    context "when no user is logged in" do
      it{ should redirect_to new_user_session_path }
    end

    context "when user is logged in" do
      let(:current_user){ create(:user) }
      it{ should redirect_to success_project_path(project) }
    end
  end

  describe 'GET success' do
    let(:project){ create(:project) }

    context 'when has successful_created session' do
      before do
        session[:successful_created] = project.id
        get :success, id: project
      end

      it { expect(response).to be_success }

      it 'should set successful_created session as false' do
        expect(session[:successful_created]).to be_false
      end
    end

    context 'when does not have successful_created session' do
      before do
        session[:sucessful_created] = false
        get :success, id: project
      end

      it { expect(response).to redirect_to project_path(project) }
    end
  end

  describe "DELETE destroy" do
    before do
      delete :destroy, id: project, locale: :pt
    end

    context "when user is a guest" do
      it { Project.all.include?(project).should be_true }
    end

    context "when user is a project owner" do
      let(:current_user){ project.user }
      it { Project.all.include?(project).should be_true }
    end

    context "when user is a registered user" do
      let(:current_user){ create(:user, admin: false) }
      it { Project.all.include?(project).should be_true }
    end

    context "when user is an admin" do
      let(:current_user){ create(:user, admin: true) }
      it { Project.all.include?(project).should be_false }
    end
  end

  describe 'GET index' do
    before do
      controller.stub(:last_tweets).and_return([])
      get :index
    end
    it { should be_success }

    describe 'staging env' do
      before do
        request.stub(:protocol).and_return("http://")
        request.stub(:host).and_return("staging.neighbor.ly")
        request.stub(:port).and_return(80)
        request.stub(:port_string).and_return(":80")
        request.stub(:path).and_return("/")
      end

      it 'should require basic auth' do
        get :index
        expect(response.status).to eq 401
      end
    end

    describe 'users without email' do
      let(:current_user) { create(:user) }

      before do
        current_user.update email: "<EMAIL>"
        get :index
      end

      it { should redirect_to set_email_users_path }
    end
  end

{'fraction_non_alphanumeric': 0.10052717687693147, 'fraction_numerical': 0.0016360661697873114, 'mean_word_length': 2.916014234875445, 'pattern_counts': {'":': 1, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6192345', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1604, 'n_words': 477}