<commit_before>require 'rails_helper'

RSpec.describe BookclubsController, :type => :controller do

  describe 'GET #index' do 
    context "when visiting as a user" do
      before :each do
        user = create(:user)
        session[:user_id] = user.id
      end

      it "assigns all bookclubs to @bookclubs" do 
        bookclubs = Bookclub.all 
        get :index
        expect(assigns(:bookclubs)).to eq bookclubs
      end

      it "expects response to be successful" do
        get :index
        expect(response).to be_success
      end

      it "renders the :index template" do 
        get :index
        expect(response).to render_template("bookclubs/index")
      end

      it "assigns a new bookclub to @bookclub for the form" do
        get :index
        expect(assigns(:bookclub)).to be_a Bookclub
      end
    end

    context "when visiting as a guest user" do
      it "redirects to home path" do
        get :index
        expect(response).to redirect_to home_path
      end
    end
  end

  describe "POST #create" do

    context "valid bookclub parameters" do
      it "creates a new bookclub" do
        expect{ post :create, bookclub: attributes_for(:bookclub) }.to change(Bookclub, :count).by(1)
      end

      it "assigns false to @errors" do
        post :create, bookclub: attributes_for(:bookclub) 
        expect(assigns(:errors)).to_not be true 
      end
    end

    context "invalid bookclub parameters" do
      it "assigns true to @errors" do
        post :create, bookclub: {name: nil}
        expect(assigns(:errors)).to_not be true 
      end

      it "does not create a new bookclub in the database" do
        expect{ post :create, bookclub: {name: nil} }.to change(Bookclub, :count).by(0)
      end
    end

  end


end<commit_msg>Update specs for JSON responses<commit_after>require 'rails_helper'

RSpec.describe BookclubsController, :type => :controller do

  describe 'GET #index' do 
    context "when visiting as a user" do
      before :each do
        user = create(:user)
        session[:user_id] = user.id
      end

      it "expects response to be successful" do
        get :index
        expect(response).to be_success
      end

      it "renders the :index template" do 
        get :index
        expect(response).to render_template("bookclubs/index")
      end

      it "assigns a new bookclub to @bookclub for the form" do
        get :index
        expect(assigns(:bookclub)).to be_a Bookclub
      end
    end

    context "when visiting as a guest user" do
      it "redirects to home path" do
        get :index
        expect(response).to redirect_to home_path
      end
    end
  end

  describe 'GET #all' do

    let(:bookclubs) { Bookclub.all }

    it "assigns all bookclubs to @bookclubs" do 
      get :all
      expect(assigns(:bookclubs)).to eq bookclubs
    end

    it "returns JSON-formatted bookclubs" do
      get :all
      expect(response.body).to have_content bookclubs.to_json
    end
  end

  describe "POST #create" do

    context "valid bookclub parameters" do
      it "expects response to be successful" do
        post :create, bookclub: attributes_for(:bookclub) 
        expect(response.status).to eq 200
      end

      it "creates a new bookclub" do
        expect{ post :create, bookclub: attributes_for(:bookclub) }.to change(Bookclub, :count).by(1)
      end
    end

    context "invalid bookclub parameters" do
      it "returns a 422 status" do
        post :create, bookclub: {name: nil}
        expect(response.status).to eq 422
      end

      it "does not create a new bookclub in the database" do
        expect{ post :create, bookclub: {name: nil} }.to change(Bookclub, :count).by(0)
      end
    end

  end


end
{'fraction_non_alphanumeric': 0.08134867540808134, 'fraction_numerical': 0.0034787262510034785, 'mean_word_length': 2.3404825737265416, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4617768', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1095, 'n_words': 394}