<commit_before>require 'test_helper'
require 'roar/decorator'

class DecoratorTest < MiniTest::Spec
  describe "Decorator" do
    it "exposes ::prepare" do
      class SongRepresentation < Roar::Decorator
        include Roar::Representer::JSON

        property :name
      end

      SongRepresentation.prepare(OpenStruct.new(:name => "Not The Same")).to_hash.must_equal({"name"=>"Not The Same"})
    end
  end

  describe "Hypermedia modules" do
    representer_for do
      link(:self) { "http://self" } # TODO: test with Collection::JSON, too.
    end

    let (:model) { Object.new }
    let (:model_with_links) { model.singleton_class.instance_eval { attr_accessor :links }; model }

    describe "JSON" do
      let (:decorator) { rpr_mod = rpr
        Class.new(Roar::Decorator) do
          include rpr_mod
        end }

      it "rendering links works" do<commit_msg>cleanup test.<commit_after>require 'test_helper'
require 'roar/decorator'

class DecoratorTest < MiniTest::Spec
  class SongRepresentation < Roar::Decorator
    include Roar::Representer::JSON

    property :name
  end

  describe "Decorator" do
    let (:song) { OpenStruct.new(:name => "Not The Same") }

    it "exposes ::prepare" do
      SongRepresentation.prepare(song).to_hash.must_equal({"name"=>"Not The Same"})
    end
  end

  describe "Hypermedia modules" do
    representer_for do
      link(:self) { "http://self" } # TODO: test with Collection::JSON, too.
    end

    let (:model) { Object.new }
    let (:model_with_links) { model.singleton_class.instance_eval { attr_accessor :links }; model }

    describe "JSON" do
      let (:decorator) { rpr_mod = rpr
        Class.new(Roar::Decorator) do
          include rpr_mod
        end }

      it "rendering links works" do
{'fraction_non_alphanumeric': 0.11425339366515837, 'fraction_numerical': 0.0, 'mean_word_length': 3.142857142857143, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6682093', 'n_tokens_mistral': 581, 'n_tokens_neox': 552, 'n_words': 143}