<commit_before>require File.dirname(__FILE__) + '/spec_helper'

require 'sinatra'
require 'sinatra/test/rspec'
require Integrity.root / 'app'


describe 'Web App' do
  include AppSpecHelper

  before(:each) do
    Integrity.stub!(:new)
    disable_basic_auth!
  end

  after(:each) { @project = nil }

  describe 'With basic auth enabled' do
    before(:each) do
      enable_basic_auth!
    end

    it 'should propose to login if not logged in' do
      get_it '/'
      @response.should have_tag('#footer a[@href="/login"]', 'Log In')
    end

    it 'should say hello to the logged in user' do
      get_it '/', :env => {'REMOTE_USER' => 'user'}
      @response.should have_tag('strong', 'user')
    end
  end

  describe 'With basic auth disabled' do
    before(:each) do
      disable_basic_auth!
    end

    it 'should not display anything related to auth' do
      get_it '/'
      @response.should_not have_tag('#footer')
    end
  end

  describe "GET /" do
    describe "with no project available" do
      before do
        Project.stub!(:all).and_return([])
      end

      it "should be success" do
        get_it "/"
        status.should == 200
      end

      it "should look for projects in the db" do
        Project.should_receive(:all).and_return([])
        get_it "/"
      end

      it "should tell you that you have no projects" do
        get_it "/"
        @response.should have_tag(".blank_slate", /none yet/i)
      end

      it "should have a link to add a new project" do
        get_it "/"
        @response.should have_tag(".blank_slate a[@href=/new]", /create your first project/i)
      end
    end

    describe "with available projects" do
      before do
        @project_1 = stub("project", :name => "The 1st Project", :permalink => "the-1st-project", :status => :success, :building? => true, :last_build => mock_build)
        @project_2 = stub("project", :name => "The 2nd Project", :permalink => "the-2nd-project", :status => :failed, :building? => false, :last_build => mock_build)
        Project.stub!(:all).and_return([@project_1, @project_2])
      end

      it "should be success" do
        get_it "/"
        status.should == 200
      end

      it "should load the public projects from the db" do<commit_msg>Cleaned up some of the specs slightly (@response.should -> body.should when testing for tag presence)<commit_after>require File.dirname(__FILE__) + '/spec_helper'

require 'sinatra'
require 'sinatra/test/rspec'
require Integrity.root / 'app'


describe 'Web App' do
  include AppSpecHelper

  before(:each) do
    Integrity.stub!(:new)
    disable_basic_auth!
  end

  after(:each) { @project = nil }

  describe 'With basic auth enabled' do
    before(:each) do
      enable_basic_auth!
    end

    it 'should propose to login if not logged in' do
      get_it '/'
      body.should have_tag('#footer a[@href="/login"]', 'Log In')
    end

    it 'should say hello to the logged in user' do
      get_it '/', :env => {'REMOTE_USER' => 'user'}
      body.should have_tag('strong', 'user')
    end
  end

  describe 'With basic auth disabled' do
    before(:each) do
      disable_basic_auth!
    end

    it 'should not display anything related to auth' do
      get_it '/'
      body.should_not have_tag('#footer')
    end
  end

  describe "GET /" do
    describe "with no project available" do
      before do
        Project.stub!(:all).and_return([])
      end

      it "should be success" do
        get_it "/"
        status.should == 200
      end

      it "should look for projects in the db" do
        Project.should_receive(:all).and_return([])
        get_it "/"
      end

      it "should tell you that you have no projects" do
        get_it "/"
        body.should have_tag(".blank_slate", /none yet/i)
      end

      it "should have a link to add a new project" do
        get_it "/"
        body.should have_tag(".blank_slate a[@href=/new]", /create your first project/i)
      end
    end

    describe "with available projects" do
      before do
        @project_1 = stub("project", :name => "The 1st Project", :permalink => "the-1st-project", :status => :success, :building? => true, :last_build => mock_build)
        @project_2 = stub("project", :name => "The 2nd Project", :permalink => "the-2nd-project", :status => :failed, :building? => false, :last_build => mock_build)
        Project.stub!(:all).and_return([@project_1, @project_2])
      end

      it "should be success" do
        get_it "/"
        status.should == 200
      end

      it "should load the public projects from the db" do
{'fraction_non_alphanumeric': 0.12013057671381937, 'fraction_numerical': 0.006093579978237214, 'mean_word_length': 2.55177743431221, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '4776844', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1403, 'n_words': 456}