<commit_before># encoding: utf-8
require 'test_helper'
require 'test_models'

class TestEmbedsRenderPipeline
  attr_accessor :represented
  include HalApi::Representer::Embeds::HalApiRailsRenderPipeline
end

EmbedsTest = Struct.new(:title)

describe HalApi::Representer::Embeds do
  let(:helper) { class TestUriMethods; include Embeds; end.new }
  let(:t_object) { TestObject.new("test", true) }
  let(:mapper) { TestEmbedsRenderPipeline.new.tap { |m| m.represented = t_object } }
  let(:repr_binding) do
    Struct.
      new(:as, :embedded, :zoom).
      new(TestOption.new('t:test'), true, nil).
      tap do |b|
        b.define_singleton_method(:evaluate_option) { |*| 'prop_name' }
      end
  end

  describe "non embedded property" do
    let (:non_embed_binding) { repr_binding.tap{|b| b.embedded = false } }

    it "is never suppressed" do
      mapper.suppress_embed?(non_embed_binding, {options: {}, binding: repr_binding}).must_equal false
    end
  end

  describe "default zoom" do
    let (:default_binding) { repr_binding.tap{|b| b.zoom = nil } }

    it "is not suppressed by default" do
      mapper.suppress_embed?(default_binding, {options: {}, binding: repr_binding}).must_equal false
    end

    it "is suppressed when specifically unrequested" do
      mapper.suppress_embed?(default_binding,{options: {zoom: ['t:none']}, binding: repr_binding} ).must_equal true
    end
  end

  describe "zoom: true" do
    let (:true_binding) { repr_binding.tap{|b| b.zoom = true } }

    it "is not suppressed by default" do
      mapper.suppress_embed?(true_binding, {options: {}, binding: repr_binding}).must_equal false
    end

    it "is suppressed when specifically unrequested" do
      mapper.suppress_embed?(true_binding, {options: {zoom: ['t:none']}, binding: repr_binding}).must_equal true
    end

    it "is unsuppressed when requested" do
      mapper.suppress_embed?(true_binding, {options: {zoom: ['t:test']}, binding: repr_binding}).must_equal false
    end
  end

  describe "zoom: always" do
    let (:always_binding) { repr_binding.tap{|b| b.zoom = :always } }

    it "is not suppressed when specifically unrequested" do
      mapper.suppress_embed?(always_binding, {options: {zoom: ['t:test']}, binding: repr_binding}).must_equal false
    end
  end

  describe "zoom: false" do<commit_msg>cache the prop name in the method's closure<commit_after># encoding: utf-8
require 'test_helper'
require 'test_models'

class TestEmbedsRenderPipeline
  attr_accessor :represented
  include HalApi::Representer::Embeds::HalApiRailsRenderPipeline
end

EmbedsTest = Struct.new(:title)

describe HalApi::Representer::Embeds do
  let(:helper) { class TestUriMethods; include Embeds; end.new }
  let(:t_object) { TestObject.new("test", true) }
  let(:mapper) { TestEmbedsRenderPipeline.new.tap { |m| m.represented = t_object } }
  let(:prop_name) { 'prop_name' }
  let(:repr_binding) do
    p = prop_name
    Struct.
      new(:as, :embedded, :zoom).
      new(TestOption.new('t:test'), true, nil).
      tap do |b|
        b.define_singleton_method(:evaluate_option) { |*| p }
      end
  end

  describe "non embedded property" do
    let (:non_embed_binding) { repr_binding.tap{|b| b.embedded = false } }

    it "is never suppressed" do
      mapper.suppress_embed?(non_embed_binding, {options: {}, binding: repr_binding}).must_equal false
    end
  end

  describe "default zoom" do
    let (:default_binding) { repr_binding.tap{|b| b.zoom = nil } }

    it "is not suppressed by default" do
      mapper.suppress_embed?(default_binding, {options: {}, binding: repr_binding}).must_equal false
    end

    it "is suppressed when specifically unrequested" do
      mapper.suppress_embed?(default_binding,{options: {zoom: ['t:none']}, binding: repr_binding} ).must_equal true
    end
  end

  describe "zoom: true" do
    let (:true_binding) { repr_binding.tap{|b| b.zoom = true } }
    let (:prop_name) { 't:test'}

    it "is not suppressed by default" do
      mapper.suppress_embed?(true_binding, {options: {}, binding: repr_binding}).must_equal false
    end

    it "is suppressed when specifically unrequested" do
      mapper.suppress_embed?(true_binding, {options: {zoom: ['t:none']}, binding: repr_binding}).must_equal true
    end

    it "is unsuppressed when requested" do
      mapper.suppress_embed?(true_binding, {options: {zoom: ['t:test']}, binding: repr_binding}).must_equal false
    end
  end

  describe "zoom: always" do
    let (:always_binding) { repr_binding.tap{|b| b.zoom = :always } }

    it "is not suppressed when specifically unrequested" do
      mapper.suppress_embed?(always_binding, {options: {zoom: ['t:test']}, binding: repr_binding}).must_equal false
    end
  end

  describe "zoom: false" do
{'fraction_non_alphanumeric': 0.12302839116719243, 'fraction_numerical': 0.0004206098843322818, 'mean_word_length': 4.086631016042781, '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': '958008', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1508, 'n_words': 395}