<commit_before>require 'spec_helper'

# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator.  If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails.  There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec.  Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.

describe PagesController do

  # This should return the minimal set of attributes required to create a valid
  # Page. As you add validations to Page, be sure to
  # adjust the attributes here as well.
  let(:valid_attributes) { { "name" => "MyString", "permalink" => "about" } }

  # This should return the minimal set of values that should be in the session
  # in order to pass any filters (e.g. authentication) defined in
  # PagesController. Be sure to keep this updated too.
  let(:valid_session) { {} }

  before(:each) do
    controller.stub(:admin?).and_return(true)
  end

  describe "GET index" do
    it "assigns all pages as @pages" do
      page = Page.create! valid_attributes
      get :index, {}
      assigns(:pages).should eq([page])
    end

    it 'should use a full-width layout' do
      get :index, {}
      response.should render_template 'layouts/full_width'
    end
  end

  describe "GET show", :helpers => :controllers do
    before :each do
      make_current_user_admin
      @valid_page = double('Page', :name => 'About Us', :permalink => 'about', :content => 'blah blah')
      @error_page = double('Page')
    end

    after(:each) {response.should render_template 'layouts/full_width'}

    it 'assigns @admin if current_user is admin' do
      Page.stub(:find_by_permalink!)
      get :show, { :id => 'about' }
      assigns(:admin).should be_true
    end

    it 'assigns @page if params[id] is a valid permalink' do
      Page.should_receive(:find_by_permalink!).with('about').and_return(@valid_page)
      get :show, { :id => 'about'}
      assigns(:page).should eq @valid_page
    end

    it '200: respond code should be appropriate for page' do
      Page.stub(:find_by_permalink!)
      get :show, { :id => 'about' }
      response.status.should eq 200
    end
  end

  describe 'GET new' do
    it 'assigns a new page as @page' do
      get :new, {}
      assigns(:page).should be_a_new(Page)
    end

    it 'should use a full-width layout' do
      get :new, {}
      response.should render_template 'layouts/full_width'
    end
  end

  describe 'GET edit' do
    it "assigns the requested page as @page" do
      page = Page.create! valid_attributes
      get :edit, {:id => page.to_param}
      assigns(:page).should eq(page)
    end

    it 'should use a full-width layout' do
      page = Page.create! valid_attributes
      get :edit, {:id => page.to_param}
      response.should render_template 'layouts/full_width'
    end
  end

  describe "POST create" do
    describe "with valid params" do
      it "creates a new Page" do
        expect {
          post :create, {:page => valid_attributes}
        }.to change(Page, :count).by(1)
      end

      it "assigns a newly created page as @page" do
        post :create, {:page => valid_attributes}
        assigns(:page).should be_a(Page)
        assigns(:page).should be_persisted
      end

      it "redirects to the created page" do
        post :create, {:page => valid_attributes}
        response.should redirect_to(Page.last)
      end
    end

    describe "with invalid params" do
      it "assigns a newly created but unsaved page as @page" do
        # Trigger the behavior that occurs when invalid params are submitted
        Page.any_instance.stub(:save).and_return(false)
        post :create, {:page => { "name" => "invalid value" }}
        assigns(:page).should be_a_new(Page)
      end

      it "re-renders the 'new' template" do
        # Trigger the behavior that occurs when invalid params are submitted
        Page.any_instance.stub(:save).and_return(false)
        post :create, {:page => { "name" => "invalid value" }}
        response.should render_template("new")
      end
    end
  end

  describe "PUT update" do
    describe "with valid params" do
      it "updates the requested page" do
        page = Page.create! valid_attributes
        # Assuming there are no other pages in the database, this
        # specifies that the Page created on the previous line
        # receives the :update_attributes message with whatever params are
        # submitted in the request.
        Page.any_instance.should_receive(:update_attributes).with({ "name" => "MyString" })
        put :update, {:id => page.to_param, :page => { "name" => "MyString" }}
      end

      it "assigns the requested page as @page" do
        page = Page.create! valid_attributes
        put :update, {:id => page.to_param, :page => valid_attributes}
        assigns(:page).should eq(page)
      end

      it "redirects to the page" do
        page = Page.create! valid_attributes
        put :update, {:id => page.to_param, :page => valid_attributes}
        response.should redirect_to(page)
      end
    end

    describe "with invalid params" do
      it "assigns the page as @page" do
        page = Page.create! valid_attributes
        # Trigger the behavior that occurs when invalid params are submitted
        Page.any_instance.stub(:save).and_return(false)
        put :update, {:id => page.to_param, :page => { "name" => "invalid value" }}
        assigns(:page).should eq(page)
      end

      it "re-renders the 'edit' template" do
        page = Page.create! valid_attributes
        # Trigger the behavior that occurs when invalid params are submitted
        Page.any_instance.stub(:save).and_return(false)
        put :update, {:id => page.to_param, :page => { "name" => "invalid value" }}
        response.should render_template("edit")
      end
    end
  end

  describe "DELETE destroy" do
    it "destroys the requested page" do
      page = Page.create! valid_attributes
      expect {
        delete :destroy, {:id => page.to_param}
      }.to change(Page, :count).by(-1)
    end

    it "redirects to the pages list" do
      page = Page.create! valid_attributes
      delete :destroy, {:id => page.to_param}
      response.should redirect_to(pages_url)
    end
  end

end
<commit_msg>Added a failing rspec test<commit_after>require 'spec_helper'

# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator.  If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails.  There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec.  Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.

describe PagesController do

  # This should return the minimal set of attributes required to create a valid
  # Page. As you add validations to Page, be sure to
  # adjust the attributes here as well.
  let(:valid_attributes) { { "name" => "MyString", "permalink" => "about" } }

  # This should return the minimal set of values that should be in the session
  # in order to pass any filters (e.g. authentication) defined in
  # PagesController. Be sure to keep this updated too.
  let(:valid_session) { {} }

  before(:each) do
    controller.stub(:admin?).and_return(true)
  end

  describe "GET index" do
    it "assigns all pages as @pages" do
      page = Page.create! valid_attributes
      get :index, {}
      assigns(:pages).should eq([page])
    end

    it 'should use a full-width layout' do
      get :index, {}
      response.should render_template 'layouts/full_width'
    end

    it "assigns the pages in alphabetical order by default" do
      page_xyz = Page.create! ({ "name" => "Xyz", "permalink" => "xyz" })
      page_abc = Page.create! ({ "name" => "Abc", "permalink" => "abc" })
      get :index, {}
      assigns(:pages).should eq([page_abc, page_xyz])
    end
  end

  describe "GET show", :helpers => :controllers do
    before :each do
      make_current_user_admin
      @valid_page = double('Page', :name => 'About Us', :permalink => 'about', :content => 'blah blah')
      @error_page = double('Page')
    end

    after(:each) {response.should render_template 'layouts/full_width'}

    it 'assigns @admin if current_user is admin' do
      Page.stub(:find_by_permalink!)
      get :show, { :id => 'about' }
      assigns(:admin).should be_true
    end

    it 'assigns @page if params[id] is a valid permalink' do
      Page.should_receive(:find_by_permalink!).with('about').and_return(@valid_page)
      get :show, { :id => 'about'}
      assigns(:page).should eq @valid_page
    end

    it '200: respond code should be appropriate for page' do
      Page.stub(:find_by_permalink!)
      get :show, { :id => 'about' }
      response.status.should eq 200
    end
  end

  describe 'GET new' do
    it 'assigns a new page as @page' do
      get :new, {}
      assigns(:page).should be_a_new(Page)
    end

    it 'should use a full-width layout' do
      get :new, {}
      response.should render_template 'layouts/full_width'
    end
  end

  describe 'GET edit' do
    it "assigns the requested page as @page" do
      page = Page.create! valid_attributes
      get :edit, {:id => page.to_param}
      assigns(:page).should eq(page)
    end

    it 'should use a full-width layout' do
      page = Page.create! valid_attributes
      get :edit, {:id => page.to_param}
      response.should render_template 'layouts/full_width'
    end
  end

  describe "POST create" do
    describe "with valid params" do
      it "creates a new Page" do
        expect {
          post :create, {:page => valid_attributes}
        }.to change(Page, :count).by(1)
      end

      it "assigns a newly created page as @page" do
        post :create, {:page => valid_attributes}
        assigns(:page).should be_a(Page)
        assigns(:page).should be_persisted
      end

      it "redirects to the created page" do
        post :create, {:page => valid_attributes}
        response.should redirect_to(Page.last)
      end
    end

    describe "with invalid params" do
      it "assigns a newly created but unsaved page as @page" do
        # Trigger the behavior that occurs when invalid params are submitted
        Page.any_instance.stub(:save).and_return(false)
        post :create, {:page => { "name" => "invalid value" }}
        assigns(:page).should be_a_new(Page)
      end

      it "re-renders the 'new' template" do
        # Trigger the behavior that occurs when invalid params are submitted
        Page.any_instance.stub(:save).and_return(false)
        post :create, {:page => { "name" => "invalid value" }}
        response.should render_template("new")
      end
    end
  end

  describe "PUT update" do
    describe "with valid params" do
      it "updates the requested page" do
        page = Page.create! valid_attributes
        # Assuming there are no other pages in the database, this
        # specifies that the Page created on the previous line
        # receives the :update_attributes message with whatever params are
        # submitted in the request.
        Page.any_instance.should_receive(:update_attributes).with({ "name" => "MyString" })
        put :update, {:id => page.to_param, :page => { "name" => "MyString" }}
      end

      it "assigns the requested page as @page" do
        page = Page.create! valid_attributes
        put :update, {:id => page.to_param, :page => valid_attributes}
        assigns(:page).should eq(page)
      end

      it "redirects to the page" do
        page = Page.create! valid_attributes
        put :update, {:id => page.to_param, :page => valid_attributes}
        response.should redirect_to(page)
      end
    end

    describe "with invalid params" do
      it "assigns the page as @page" do
        page = Page.create! valid_attributes
        # Trigger the behavior that occurs when invalid params are submitted
        Page.any_instance.stub(:save).and_return(false)
        put :update, {:id => page.to_param, :page => { "name" => "invalid value" }}
        assigns(:page).should eq(page)
      end

      it "re-renders the 'edit' template" do
        page = Page.create! valid_attributes
        # Trigger the behavior that occurs when invalid params are submitted
        Page.any_instance.stub(:save).and_return(false)
        put :update, {:id => page.to_param, :page => { "name" => "invalid value" }}
        response.should render_template("edit")
      end
    end
  end

  describe "DELETE destroy" do
    it "destroys the requested page" do
      page = Page.create! valid_attributes
      expect {
        delete :destroy, {:id => page.to_param}
      }.to change(Page, :count).by(-1)
    end

    it "redirects to the pages list" do
      page = Page.create! valid_attributes
      delete :destroy, {:id => page.to_param}
      response.should redirect_to(pages_url)
    end
  end

end

{'fraction_non_alphanumeric': 0.09580125962211336, 'fraction_numerical': 0.001119664100769769, 'mean_word_length': 2.8375402792696027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 75, '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': '3213065', 'n_tokens_mistral': 4208, 'n_tokens_neox': 4061, 'n_words': 1558}