<commit_before>require 'helper'

require 'rack/test'
require 'action_controller/railtie'

require 'neo/rails/exposure'


class ExposureTestController < ActionController::Base
  include Neo::Rails::Exposure

  exposes :a, :b

  def foo
    render :text => "bar"
  end

  def expose_via_value
    expose :a, "a"
    expose :b, "b"
    render :inline => %{ar=#{exposures.a},ah=<%= a %>,br=#{exposures.b},bh=<%= b %>}
  end

  def expose_via_block
    expose(:a) { "a" }
    expose(:b) { "b" }
    render :inline => %{ar=#{exposures.a},ah=<%= a %>,br=#{exposures.b},bh=<%= b %>}
  end

  def exposes_via_value_with_template
    expose(:a, "a")
    expose(:b) { "b" }
    template = File.expand_path(File.join("..", "fixtures", "views", "exposes_via_value_with_template"), __FILE__)
    render :file => template
  end

  def expose_with_error
    expose(:unknown) { "unknown" }
  end

  def expose_nil_value
    expose(:a) { nil }
    render :inline => [ exposed?(:a), exposed?(:b) ].inspect
  end
end

class OtherExposureTestController < ExposureTestController
  include Neo::Rails::Exposure

  exposes :c

  def bar
    expose :a, "a"
    expose :b, "b"
    expose :c, "c"

    render :inline => "<%= a %>;<%= b %>;<%= c %>"
  end

end

class ATestController < ExposureTestController
  exposes :z

  def baz
    expose :z, "z"
    render :inline => "<%= z %>"
  end
end

class BTestController < ExposureTestController
  exposes :z

  def baz
    expose :z, "z"
    render :inline => "<%= z %>"
  end
end

class ExposureTestApp < Rails::Application
  routes.draw do
    get ":action" => ExposureTestController
    get "other/:action" => OtherExposureTestController
    get "a/:action" => ATestController
    get "b/:action" => BTestController
  end

  config.secret_key_base = "a" * 32
  config.secret_token = "a" * 32
  config.session_store :disabled
  config.middleware.delete Rails::Rack::Logger
  config.middleware.delete ActionDispatch::ShowExceptions
  config.middleware.delete ActionDispatch::DebugExceptions
end

class ExposureTest < NeoRailsCase
  include Rack::Test::Methods

  def app
    ExposureTestApp
  end

  test "should expose variable per value" do
    get "expose_via_value"
    assert_equal "ar=a,ah=a,br=b,bh=b", last_response.body
  end

  test "should expose variable per block" do
    get "expose_via_block"
    assert_equal "ar=a,ah=a,br=b,bh=b", last_response.body<commit_msg>Kill deprecation warning about usage of dynamic segments<commit_after>require 'helper'

require 'rack/test'
require 'action_controller/railtie'

require 'neo/rails/exposure'


class ExposureTestController < ActionController::Base
  include Neo::Rails::Exposure

  exposes :a, :b

  def foo
    render :text => "bar"
  end

  def expose_via_value
    expose :a, "a"
    expose :b, "b"
    render :inline => %{ar=#{exposures.a},ah=<%= a %>,br=#{exposures.b},bh=<%= b %>}
  end

  def expose_via_block
    expose(:a) { "a" }
    expose(:b) { "b" }
    render :inline => %{ar=#{exposures.a},ah=<%= a %>,br=#{exposures.b},bh=<%= b %>}
  end

  def exposes_via_value_with_template
    expose(:a, "a")
    expose(:b) { "b" }
    template = File.expand_path(File.join("..", "fixtures", "views", "exposes_via_value_with_template"), __FILE__)
    render :file => template
  end

  def expose_with_error
    expose(:unknown) { "unknown" }
  end

  def expose_nil_value
    expose(:a) { nil }
    render :inline => [ exposed?(:a), exposed?(:b) ].inspect
  end
end

class OtherExposureTestController < ExposureTestController
  include Neo::Rails::Exposure

  exposes :c

  def bar
    expose :a, "a"
    expose :b, "b"
    expose :c, "c"

    render :inline => "<%= a %>;<%= b %>;<%= c %>"
  end

end

class ATestController < ExposureTestController
  exposes :z

  def baz
    expose :z, "z"
    render :inline => "<%= z %>"
  end
end

class BTestController < ExposureTestController
  exposes :z

  def baz
    expose :z, "z"
    render :inline => "<%= z %>"
  end
end

class ExposureTestApp < Rails::Application
  routes.draw do
    ExposureTestController.action_methods.each do |action|
      get action => "exposure_test##{action}"
    end
    get "other/bar" => "other_exposure_test#bar"
    get "a/baz" => "a_test#baz"
    get "b/baz" => "b_test#baz"
  end

  config.secret_key_base = "a" * 32
  config.secret_token = "a" * 32
  config.session_store :disabled
  config.middleware.delete Rails::Rack::Logger
  config.middleware.delete ActionDispatch::ShowExceptions
  config.middleware.delete ActionDispatch::DebugExceptions
end

class ExposureTest < NeoRailsCase
  include Rack::Test::Methods

  def app
    ExposureTestApp
  end

  test "should expose variable per value" do
    get "expose_via_value"
    assert_equal "ar=a,ah=a,br=b,bh=b", last_response.body
  end

  test "should expose variable per block" do
    get "expose_via_block"
    assert_equal "ar=a,ah=a,br=b,bh=b", last_response.body
{'fraction_non_alphanumeric': 0.1408997955010225, 'fraction_numerical': 0.0016359918200408998, 'mean_word_length': 3.767056530214425, 'pattern_counts': {'":': 1, '<': 33, '<?xml version=': 0, '>': 45, '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': '1641630', 'n_tokens_mistral': 1839, 'n_tokens_neox': 1729, 'n_words': 418}