<commit_before>require './test/test_helper'

describe 'ApiView::Base' do

  describe 'class methods' do
    describe '#render' do
      class RenderTestApiView < ::ApiView::Base
        attributes :abbreviation, :full_name, :location
      end

      it "works" do
        obj      = OpenStruct.new(abbreviation: 'hey', full_name: '<NAME>', location: 'loc')
        res      = RenderTestApiView.render(obj, nil)
        expected = {"abbreviation"=>"hey", "full_name"=>"full name", "location"=>"loc"}
        MultiJson.load(res).must_equal expected
      end
    end
  end

  describe 'instance methods' do

    describe '#convert' do
      class ConvertSimpleApiView < ::ApiView::Base
        attributes :some_value

        def instance_convert
          field :simple, true
        end
      end

      class ConvertTestApiView < ::ApiView::Base
        attributes :abbreviation, :full_name, :location

        def instance_convert
          field :away_team, 'away_team'
          field :simple_view, object.simple_view, via: ConvertSimpleApiView
        end
      end

      it "works" do
        simple_view = OpenStruct.new(some_value: 'very simple value')
        obj         = OpenStruct.new(abbreviation: 'hey', full_name: '<NAME>', location: 'loc', simple_view: simple_view)
        res         = ConvertTestApiView.render(obj, nil)
        expected    = {"abbreviation"=>"hey", "full_name"=>"<NAME>", "location"=>"loc", "away_team"=>"away_team", "simple_view"=>{"some_value"=>"very simple value", "simple"=>true}}
        MultiJson.load(res).must_equal expected
      end
    end
  end
end<commit_msg>adjust tests<commit_after>require './test/test_helper'

describe 'ApiView::Base' do

  describe 'class methods' do
    describe '#render' do
      class RenderTestApiView < ::ApiView::Base
        attributes :abbreviation, :full_name, :location
      end

      it "works" do
        obj      = OpenStruct.new(abbreviation: 'hey', full_name: '<NAME>', location: 'loc')
        res      = RenderTestApiView.render(obj)
        expected = {"abbreviation"=>"hey", "full_name"=>"<NAME>", "location"=>"loc"}
        MultiJson.load(res).must_equal expected
      end
    end
  end

  describe 'instance methods' do

    describe '#convert' do
      class ConvertSimpleApiView < ::ApiView::Base
        attributes :some_value

        def instance_convert
          field :simple, true
        end
      end

      class ConvertTestApiView < ::ApiView::Base
        attributes :abbreviation, :full_name, :location

        def instance_convert
          field :away_team, 'away_team'
          field :simple_view, object.simple_view, via: ConvertSimpleApiView
        end
      end

      it "works" do
        simple_view = OpenStruct.new(some_value: 'very simple value')
        obj         = OpenStruct.new(abbreviation: 'hey', full_name: '<NAME>', location: 'loc', simple_view: simple_view)
        res         = ConvertTestApiView.render(obj)
        expected    = {"abbreviation"=>"hey", "full_name"=>"<NAME>", "location"=>"loc", "away_team"=>"away_team", "simple_view"=>{"some_value"=>"very simple value", "simple"=>true}}
        MultiJson.load(res).must_equal expected
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12274143302180686, 'fraction_numerical': 0.0, 'mean_word_length': 2.8455089820359283, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 30, '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': '2310820', 'n_tokens_mistral': 980, 'n_tokens_neox': 949, 'n_words': 229}