<commit_before>require_relative '../../../spec_helper'

describe Api::V1::PlayersController do
  render_views

  before do
    @player1 = FactoryGirl.create(:player, first_name: "Joe", last_name: "Smith", team_id: 1)
    @player2 = FactoryGirl.create(:player, first_name: "Bob", last_name: "Jones", team_id: 2)
    @player3 = FactoryGirl.create(:player, first_name: "Peter", last_name: "Wilson", team_id: 3)
  end

  describe "#index" do

    before do
      get :index, :format => :json
    end

    it "should retrieve status code of 200" do
      response.response_code.should == 200
    end

    it "should retrieve license header" do
      response.header["X-LS-License"].should == "All Rights Reserved"
    end

    it "should retrieve application name header" do
      response.header["X-LS-Application"].should == "league-server"
    end

    it "should retrieve records-returned header" do
      response.header["X-LS-Records-Returned"].should be_present
    end

    it "should retrieve a content-type of json" do
      response.header['Content-Type'].should include 'application/json'
    end

    it "should retrieve list of players" do
      players = Player.all
      players.count.should == 3

      response.body.should include(@player1.id.to_s)
      response.body.should include(@player2.id.to_s)
      response.body.should include(@player3.id.to_s)
      response.body.should include('<NAME>')
      response.body.should include('<NAME>')
      response.body.should include('<NAME>')
    end
  end

  describe "#show" do

    before do
      get :show, id: @player1.id, :format => :json
    end

    it "should retrieve status code of 200" do
      response.response_code.should == 200
    end

    it "should retrieve application name header" do
      response.header["X-LS-Application"].should == "league-server"
    end

    it "should retrieve license header" do
      response.header["X-LS-License"].should == "All Rights Reserved"
    end

    it "should retrieve records-returned header" do
      response.header["X-LS-Records-Returned"].should == "1"
    end

    it "should retrieve a content-type of json" do
      response.header['Content-Type'].should include 'application/json'
    end

    it "should retrieve a single player" do
      player = Player.where id: @player1.id
      player.count.should == 1

      response.body.should include(@player1.id.to_s)
      response.body.should include('<NAME>')
    end
  end

  describe "#create" do

    before do
      request_payload = {
        player: {
          first_name: "Buck",
          last_name: "Carradine",
          team_id: "1",
          junk: "trunk"
        }
      }

      post :create, request_payload
    end

    it "should retrieve status code of 200" do
      response.response_code.should == 200
    end

    it "should retrieve application name header" do
      response.header["X-LS-Application"].should == "league-server"
    end

    it "should retrieve license header" do
      response.header["X-LS-License"].should == "All Rights Reserved"
    end

    it "should retrieve records-returned header" do
      response.header["X-LS-Records-Returned"].should == "1"
    end

    it "should retrieve a content-type of json" do
      response.header['Content-Type'].should include 'application/json'
    end

    it "should retrieve a single player" do
      response.body.should include('<NAME>')
      response.body.should_not include('junk')
    end
  end

  describe "#update" do

    before do
      request_payload = {
        player: {
          first_name: "Buck",
          last_name: "Carradine",
          team_id: "1"
        }
      }

      put :update, id: @player1.id, request_payload
    end

    # it "should retrieve status code of 200" do
    #   response.response_code.should == 200
    # end

    # it "should retrieve application name header" do
    #   response.header["X-LS-Application"].should == "league-server"
    # end

    # it "should retrieve license header" do
    #   response.header["X-LS-License"].should == "All Rights Reserved"
    # end

    # it "should retrieve records-returned header" do
    #   response.header["X-LS-Records-Returned"].should == "1"
    # end

    # it "should retrieve a content-type of json" do
    #   response.header['Content-Type'].should include 'application/json'
    # end

    # it "should retrieve a single player" do
    #   response.body.should include('Buck')
    #   response.body.should_not include('Joe')
    # end
  end<commit_msg>only the last argument can be a bare hash<commit_after>require_relative '../../../spec_helper'

describe Api::V1::PlayersController do
  render_views

  before do
    @player1 = FactoryGirl.create(:player, first_name: "Joe", last_name: "Smith", team_id: 1)
    @player2 = FactoryGirl.create(:player, first_name: "Bob", last_name: "Jones", team_id: 2)
    @player3 = FactoryGirl.create(:player, first_name: "Peter", last_name: "Wilson", team_id: 3)
  end

  describe "#index" do

    before do
      get :index, :format => :json
    end

    it "should retrieve status code of 200" do
      response.response_code.should == 200
    end

    it "should retrieve license header" do
      response.header["X-LS-License"].should == "All Rights Reserved"
    end

    it "should retrieve application name header" do
      response.header["X-LS-Application"].should == "league-server"
    end

    it "should retrieve records-returned header" do
      response.header["X-LS-Records-Returned"].should be_present
    end

    it "should retrieve a content-type of json" do
      response.header['Content-Type'].should include 'application/json'
    end

    it "should retrieve list of players" do
      players = Player.all
      players.count.should == 3

      response.body.should include(@player1.id.to_s)
      response.body.should include(@player2.id.to_s)
      response.body.should include(@player3.id.to_s)
      response.body.should include('<NAME>')
      response.body.should include('<NAME>')
      response.body.should include('<NAME>')
    end
  end

  describe "#show" do

    before do
      get :show, id: @player1.id, :format => :json
    end

    it "should retrieve status code of 200" do
      response.response_code.should == 200
    end

    it "should retrieve application name header" do
      response.header["X-LS-Application"].should == "league-server"
    end

    it "should retrieve license header" do
      response.header["X-LS-License"].should == "All Rights Reserved"
    end

    it "should retrieve records-returned header" do
      response.header["X-LS-Records-Returned"].should == "1"
    end

    it "should retrieve a content-type of json" do
      response.header['Content-Type'].should include 'application/json'
    end

    it "should retrieve a single player" do
      player = Player.where id: @player1.id
      player.count.should == 1

      response.body.should include(@player1.id.to_s)
      response.body.should include('<NAME>')
    end
  end

  describe "#create" do

    before do
      request_payload = {
        player: {
          first_name: "Buck",
          last_name: "Carradine",
          team_id: "1",
          junk: "trunk"
        }
      }

      post :create, request_payload
    end

    it "should retrieve status code of 200" do
      response.response_code.should == 200
    end

    it "should retrieve application name header" do
      response.header["X-LS-Application"].should == "league-server"
    end

    it "should retrieve license header" do
      response.header["X-LS-License"].should == "All Rights Reserved"
    end

    it "should retrieve records-returned header" do
      response.header["X-LS-Records-Returned"].should == "1"
    end

    it "should retrieve a content-type of json" do
      response.header['Content-Type'].should include 'application/json'
    end

    it "should retrieve a single player" do
      response.body.should include('<NAME>')
    end

    it "should not add extraneous attributes" do
      response.body.should_not include('junk')
    end
  end

  describe "#update" do

    before do
      request_payload = {
        player: {
          first_name: "Buck",
          last_name: "Carradine",
          team_id: "1"
        }
      }

      put :update, { id: 1 }, request_payload
    end

    it "should retrieve status code of 200" do
      response.response_code.should == 200
    end

    it "should retrieve application name header" do
      response.header["X-LS-Application"].should == "league-server"
    end

    it "should retrieve license header" do
      response.header["X-LS-License"].should == "All Rights Reserved"
    end

    it "should retrieve records-returned header" do
      response.header["X-LS-Records-Returned"].should == "1"
    end

    it "should retrieve a content-type of json" do
      response.header['Content-Type'].should include 'application/json'
    end

    it "should retrieve a single player" do
      response.body.should include('Buck')
      response.body.should_not include('Joe')
    end
  end
{'fraction_non_alphanumeric': 0.11273969583425171, 'fraction_numerical': 0.009918448313863787, 'mean_word_length': 2.677066450567261, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '2007229', 'n_tokens_mistral': 2771, 'n_tokens_neox': 2606, 'n_words': 765}