<commit_before>require 'spec_helper'

describe OrganizationsController do
  before :suite do
    FactoryGirl.factories.clear
    FactoryGirl.find_definitions
  end
  def mock_organization(stubs={})
    (@mock_organization ||= mock_model(Organization).as_null_object).tap do |organization|
      organization.stub(stubs) unless stubs.empty?
    end
  end
  
  describe "GET search" do
    it "searches all organizations as @organizations" do
      result = [mock_organization]
      json='my markers'
      result.should_receive(:to_gmaps4rails).and_return(json)
      Organization.should_receive(:search_by_keyword).with('test').and_return(result)
      
      get :search, :q => 'test'
      response.should render_template 'index'

      assigns(:organizations).should eq([mock_organization])
      assigns(:json).should eq(json)
    end
  end


  describe "GET index" do
    it "assigns all organizations as @organizations" do
      mock_array = []
      mock_json = ""
      #this array expectation doesn't work and I don't know why
      #Array.should_receive(:to_gmaps4rails).and_return(mock_json)
      Organization.stub(:all) { mock_array }
      get :index
      assigns(:organizations).should eq(mock_array)
      assigns(:json).should eq("[]")
    end
  end

  describe "GET show" do
    it "assigns the requested organization as @organization" do
      Organization.stub(:find).with("37") { mock_organization }
      get :show, :id => "37"
      assigns(:organization).should be(mock_organization)
    end
  end

  describe "GET new" do
    context "while signed in" do
      before(:each) do
        @admin = FactoryGirl.create(:charity_worker)
        sign_in :charity_worker, @admin
      end
      it "assigns a new organization as @organization" do
        Organization.stub(:new) { mock_organization }
        get :new
        assigns(:organization).should be(mock_organization)
      end
    end
  end
<commit_msg>controller spec for redirect when not signed in and getting create new form<commit_after>require 'spec_helper'

describe OrganizationsController do
  before :suite do
    FactoryGirl.factories.clear
    FactoryGirl.find_definitions
  end
  def mock_organization(stubs={})
    (@mock_organization ||= mock_model(Organization).as_null_object).tap do |organization|
      organization.stub(stubs) unless stubs.empty?
    end
  end
  
  describe "GET search" do
    it "searches all organizations as @organizations" do
      result = [mock_organization]
      json='my markers'
      result.should_receive(:to_gmaps4rails).and_return(json)
      Organization.should_receive(:search_by_keyword).with('test').and_return(result)
      
      get :search, :q => 'test'
      response.should render_template 'index'

      assigns(:organizations).should eq([mock_organization])
      assigns(:json).should eq(json)
    end
  end


  describe "GET index" do
    it "assigns all organizations as @organizations" do
      mock_array = []
      mock_json = ""
      #this array expectation doesn't work and I don't know why
      #Array.should_receive(:to_gmaps4rails).and_return(mock_json)
      Organization.stub(:all) { mock_array }
      get :index
      assigns(:organizations).should eq(mock_array)
      assigns(:json).should eq("[]")
    end
  end

  describe "GET show" do
    it "assigns the requested organization as @organization" do
      Organization.stub(:find).with("37") { mock_organization }
      get :show, :id => "37"
      assigns(:organization).should be(mock_organization)
    end
  end

  describe "GET new" do
    context "while signed in" do
      before(:each) do
        @admin = FactoryGirl.create(:charity_worker)
        sign_in :charity_worker, @admin
      end
      it "assigns a new organization as @organization" do
        Organization.stub(:new) { mock_organization }
        get :new
        assigns(:organization).should be(mock_organization)
      end
    end
    context "while not signed in" do
      it "redirects to sign-in" do
        get :new
        expect(response).to redirect_to new_charity_worker_session_path
      end
    end
  end

{'fraction_non_alphanumeric': 0.09520331141952763, 'fraction_numerical': 0.0029218407596785976, 'mean_word_length': 3.19611848825332, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6264979', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1197, 'n_words': 314}