<commit_before># encoding: utf-8

require 'spec_helper'

describe PaginasController do
  def pagina_falla_validacion
    falla_validacion(Pagina)
  end

  def pagina_valida_siempre
    valida_siempre(Pagina)
  end

  before(:each) do
    @pagina = Factory(:pagina)
    authenticate_usuario
  end

  describe "index" do
    context "sin AJAX" do
      before(:each) { get :index }

      it { should respond_with(:success) }
      it { assigns(:paginas).should be_true }
      it { should render_with_layout(:application) }
    end

    context "con AJAX" do
      before(:each) { xhr :get, :index }

      it { should respond_with_content_type(:js) }
      it { should render_template(:index) }
      it { should respond_with(:success) }
      it { should_not render_with_layout }
    end
  end

  describe "new action" do
    before(:each) { get :new }
    it { should render_template(:new) }
  end

  describe "create action" do
    context "when model is invalid" do
      before(:each) do
        pagina_falla_validacion
        post :create, pagina: @pagina.attributes
      end

      it { should render_template(:new) }
    end

    context "when model is valid" do
      before(:each) do
        pagina_valida_siempre
        post :create, pagina: @pagina.attributes
      end
      it { should redirect_to(pagina_path(assigns(:pagina))) }
      it { should set_the_flash }
    end

    context "when using preview button" do
      context "with a normal request" do
        before(:each) do
          post :create, pagina: @pagina.attributes, preview: true
        end

        it { should render_template(:preview) }
        it { assigns(:pagina).should be_true }
      end

      context "with an AJAX request" do
        before(:each) do
          xhr :post, :create, pagina: @pagina.attributes, preview: true
        end

        it { should render_template(:preview) }
        it { should respond_with_content_type(:js) }
        it { should_not render_with_layout }
      end
    end
  end

  describe "show action" do
    before(:each) do
      get :show, id: @pagina.to_param
    end
    it { should respond_with(:success) }
  end

  describe "edit action" do
    before(:each) do
      get :edit, id: @pagina.to_param
    end
    it { should render_template(:edit) }
  end

  describe "update action" do
    context "when model is invalid" do
      before(:each) do
        pagina_falla_validacion
        put :update, id: @pagina.to_param, pagina: @pagina.attributes
      end

      it { should render_template(:edit) }
    end

    context "when model is valid" do
      before(:each) do
        pagina_valida_siempre<commit_msg>Test de que la acción de mostrar es pública.<commit_after># encoding: utf-8

require 'spec_helper'

describe PaginasController do
  def pagina_falla_validacion
    falla_validacion(Pagina)
  end

  def pagina_valida_siempre
    valida_siempre(Pagina)
  end

  before(:each) do
    @pagina = Factory(:pagina)
    authenticate_usuario
  end

  describe "index" do
    context "sin AJAX" do
      before(:each) { get :index }

      it { should respond_with(:success) }
      it { assigns(:paginas).should be_true }
      it { should render_with_layout(:application) }
    end

    context "con AJAX" do
      before(:each) { xhr :get, :index }

      it { should respond_with_content_type(:js) }
      it { should render_template(:index) }
      it { should respond_with(:success) }
      it { should_not render_with_layout }
    end
  end

  describe "new action" do
    before(:each) { get :new }
    it { should render_template(:new) }
  end

  describe "create action" do
    context "when model is invalid" do
      before(:each) do
        pagina_falla_validacion
        post :create, pagina: @pagina.attributes
      end

      it { should render_template(:new) }
    end

    context "when model is valid" do
      before(:each) do
        pagina_valida_siempre
        post :create, pagina: @pagina.attributes
      end
      it { should redirect_to(pagina_path(assigns(:pagina))) }
      it { should set_the_flash }
    end

    context "when using preview button" do
      context "with a normal request" do
        before(:each) do
          post :create, pagina: @pagina.attributes, preview: true
        end

        it { should render_template(:preview) }
        it { assigns(:pagina).should be_true }
      end

      context "with an AJAX request" do
        before(:each) do
          xhr :post, :create, pagina: @pagina.attributes, preview: true
        end

        it { should render_template(:preview) }
        it { should respond_with_content_type(:js) }
        it { should_not render_with_layout }
      end
    end
  end

  describe "show action" do
    let(:accion) { lambda { get :show, id: @pagina.to_param }}

    context "con usuario identificado" do
      before(:each) { accion.call }
      it { should respond_with(:success) }
    end

    context "sin usuario identificado" do
      before(:each) do
        sign_out @usuario
        accion.call
      end
      it { should respond_with(:success) }
    end
  end

  describe "edit action" do
    before(:each) do
      get :edit, id: @pagina.to_param
    end
    it { should render_template(:edit) }
  end

  describe "update action" do
    context "when model is invalid" do
      before(:each) do
        pagina_falla_validacion
        put :update, id: @pagina.to_param, pagina: @pagina.attributes
      end

      it { should render_template(:edit) }
    end

    context "when model is valid" do
      before(:each) do
        pagina_valida_siempre
{'fraction_non_alphanumeric': 0.08713544462336732, 'fraction_numerical': 0.0003578457684737878, 'mean_word_length': 2.509102322661645, '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': '5097295', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1721, 'n_words': 503}