<commit_before>require 'rails_helper'

module Giveaways
  RSpec.describe GiveawaysController, type: :controller do 

  	before do
  		@routes = Giveaways::Engine.routes
  	end

  	describe "GET to index" do
  		it "responds with success when admin" do
  			stub_giveaway_user_with(Giveaways::FakeAdminUser.new)

 				get :index

 				expect(response).to be_success
 			end

 			it "redirects to configured sign in path when not admin" do
 				stub_giveaway_user_with(Giveaways::FakeUser.new)

 				get :index

 				expect(response).to redirect_to '/'
 			end
  	end

  	describe "GET to show" do
  		it "responds with success when admin" do
  			giveaway = build_stubbed(:giveaway)
  			stub_giveaway_user_with(Giveaways::FakeAdminUser.new)
  			allow(Giveaway).to receive(:find).and_return(giveaway)

  			get :show, id: 1

 				expect(response).to be_success
  		end

  		it "redirects to configured sign in path when not admin" do
  			giveaway = build_stubbed(:giveaway)
  			stub_giveaway_user_with(Giveaways::FakeUser.new)
  			allow(Giveaway).to receive(:find).and_return(giveaway)
  			
  			get :show, id: 1

 				expect(response).to redirect_to '/'
  		end
  	end

	 	describe "GET to new" do
	 		it "responds with success when admin" do
	 			stub_giveaway_user_with(Giveaways::FakeAdminUser.new)

	 			get :new

				expect(response).to be_success
	 		end

	 		it "redirects to configured sign in path when not admin" do
	 			stub_giveaway_user_with(Giveaways::FakeUser.new)
	 			
	 			get :new

				expect(response).to redirect_to '/'
	 		end
	 	end

    describe "POST to create" do
      it "redirects to show when valid" do
        stub_giveaway_user_with(Giveaways::FakeAdminUser.new)
      
        post :create, giveaway: attributes_for(:giveaway)

        expect(response).to be_success
      end

      it "renders new when not valid" do          
        stub_giveaway_user_with(Giveaways::FakeAdminUser.new)
      
        post :create, giveaway: attributes_for(:giveaway).merge(title: '')

        expect(response).to be_success
      end

      it "redirects to configured sign in path when not admin" do
        stub_giveaway_user_with(Giveaways::FakeUser.new)
        
        post :create

        expect(response).to redirect_to '/'
      end
    end

    describe "GET to edit" do
      it "is success when admin" do
        giveaway = build_stubbed(:giveaway)
        allow(Giveaway).to receive(:find).and_return giveaway
        stub_giveaway_user_with(Giveaways::FakeAdminUser.new)<commit_msg>refactor controller spec<commit_after>require 'rails_helper'

module Giveaways
  RSpec.describe GiveawaysController, type: :controller do 

  	before do
  		@routes = Giveaways::Engine.routes
  	end

  	describe "GET to index" do
  		it "responds with success when admin" do
  			stub_giveaway_user_with(Giveaways::FakeAdminUser.new)

 				get :index

 				expect(response).to be_success
 			end

 			it "redirects to configured sign in path when not admin" do
 				stub_giveaway_user_with(Giveaways::FakeUser.new)

 				get :index

 				expect(response).to redirect_to '/'
 			end
  	end

  	describe "GET to show" do
  		it "responds with success when admin" do
  			giveaway = stub_giveaway
  			stub_giveaway_user_with(Giveaways::FakeAdminUser.new)
  			
  			get :show, id: 1

 				expect(response).to be_success
  		end

  		it "redirects to configured sign in path when not admin" do
  			giveaway = stub_giveaway
  			stub_giveaway_user_with(Giveaways::FakeUser.new)
  			
  			get :show, id: 1

 				expect(response).to redirect_to '/'
  		end
  	end

	 	describe "GET to new" do
	 		it "responds with success when admin" do
	 			stub_giveaway_user_with(Giveaways::FakeAdminUser.new)

	 			get :new

				expect(response).to be_success
	 		end

	 		it "redirects to configured sign in path when not admin" do
	 			stub_giveaway_user_with(Giveaways::FakeUser.new)
	 			
	 			get :new

				expect(response).to redirect_to '/'
	 		end
	 	end

    describe "POST to create" do
      it "redirects to show when valid" do
        stub_giveaway_user_with(Giveaways::FakeAdminUser.new)
      
        post :create, giveaway: attributes_for(:giveaway)

        expect(response).to be_success
      end

      it "renders new when not valid" do          
        stub_giveaway_user_with(Giveaways::FakeAdminUser.new)
      
        post :create, giveaway: attributes_for(:giveaway).merge(title: '')

        expect(response).to be_success
      end

      it "redirects to configured sign in path when not admin" do
        stub_giveaway_user_with(Giveaways::FakeUser.new)
        
        post :create

        expect(response).to redirect_to '/'
      end
    end

    describe "GET to edit" do
      it "is success when admin" do
        giveaway = stub_giveaway
        stub_giveaway_user_with(Giveaways::FakeAdminUser.new)
{'fraction_non_alphanumeric': 0.07506702412868632, 'fraction_numerical': 0.0008249123530624871, 'mean_word_length': 2.7920250195465206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3830601', 'n_tokens_mistral': 1836, 'n_tokens_neox': 1573, 'n_words': 402}