<commit_before>require 'spec_helper'

shared_examples "it does all controller actions" do
  context "get the current tenant" do
    it "should have a current_user" do
      subject.current_user.should_not be_nil
    end

    it "redirects to the current tenant" do
      controller.stub(:current_user).and_return(subject.current_user)
      get :current
      response.should redirect_to(current_user.tenant)
    end
  end

  context "get the profit sheet" do
    it "show with the current data" do
      get :profit_sheet
    end
  end

  context "get blance sheet" do
    it "show with the current data" do
      get :balance_sheet
    end
  end
end

describe TenantsController do
  pending "as admin" do
    login_admin
    it_behaves_like "it does all controller actions"
  end

  pending "as accountant" do
    login_accountant
    it_behaves_like "it does all controller actions"
  end
end<commit_msg>TenantController spec completed.<commit_after>require 'spec_helper'

shared_examples "it does all controller actions" do
  describe "get the current tenant" do
    it "should have a current_user" do
      subject.current_user.should_not be_nil
    end

    it "redirects to the current tenant" do
      controller.stub(:current_user).and_return(@current_user)
      get :current
      response.should redirect_to(@current_user.tenant)
    end
  end

  describe "get the profit sheet" do
    it "without params" do
      end_date = Date.today
      start_date = end_date.to_time.advance(:years => -1, :days => 1).to_date
      get :profit_sheet, :id => @current_user.tenant.id
      response.should render_template('profit_sheet')
      assigns(:company).should eq(@current_user.tenant.company)
      assigns(:end_date).should eq(end_date)
      assigns(:start_date).should eq(start_date)
      assigns(:dates).should eq([start_date..end_date])
    end

    it "of a custom period" do
      end_date = Date.today
      start_date = end_date.to_time.advance(:days => -14).to_date
      get :profit_sheet, {:id => @current_user.tenant.id, :by_value_period => {:from => start_date, :to => end_date}}
      response.should render_template('profit_sheet')
      assigns(:company).should eq(@current_user.tenant.company)
      assigns(:end_date).should eq(end_date)
      assigns(:start_date).should eq(start_date)
      assigns(:dates).should eq([start_date..end_date])
    end
    
    it "of a fiscal year" do
      years = [Date.today.year]
      period = @current_user.tenant.fiscal_period(Date.today.year.to_i)
      get :profit_sheet, {:id => @current_user.tenant.id, :years => years}
      response.should render_template('profit_sheet')
      assigns(:company).should eq(@current_user.tenant.company)
      assigns(:dates).should eq([period[:from]..period[:to]])
    end
  end

  describe "get blance sheet" do
    it "without params" do
      get :balance_sheet, :id => @current_user.tenant.id
      response.should render_template('balance_sheet')
      assigns(:company).should eq(@current_user.tenant.company)
      assigns(:dates).should eq([Date.today])
    end

    it "of a custom period" do
      to_date = Date.today
      get :balance_sheet,{:id => @current_user.tenant.id, :by_value_period => {:to => to_date}}
      response.should render_template('balance_sheet')
      assigns(:company).should eq(@current_user.tenant.company)
      assigns(:dates).should eq([to_date])
    end

    it "of a fiscal year" do
      to_date = Date.today
      years = [@current_user.tenant.fiscal_period(Date.today.year.to_i)[:to]]
      get :balance_sheet,{:id => @current_user.tenant.id, :years => [Date.today.year]}
      response.should render_template('balance_sheet')
      assigns(:company).should eq(@current_user.tenant.company)
      assigns(:dates).should eq(years)
    end
  end
end

describe TenantsController do
  context "as admin" do
    login_admin
    it_behaves_like "it does all controller actions"
  end

  context "as accountant" do
    login_accountant
    it_behaves_like "it does all controller actions"
  end
end
{'fraction_non_alphanumeric': 0.1031412317585951, 'fraction_numerical': 0.0009893643334157804, 'mean_word_length': 3.4586549062844543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '4430406', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1259, 'n_words': 319}