<commit_before>require 'helper'
require 'flipper/types/actor'

describe Flipper::Types::Actor do
  subject {
    thing = Struct.new(:id).new('2')
    described_class.new(thing)
  }

  let(:thing_class) {
    Class.new {
      attr_reader :id

      def initialize(identifier)
        @id = id
      end

      def admin?
        true
      end
    }
  }

  describe ".wrappable?" do
    it "returns true if actor" do
      thing = Struct.new(:id).new('1')
      actor = described_class.new(thing)
      described_class.wrappable?(actor).should be_true
    end

    it "returns true if responds to id" do
      thing = Struct.new(:id).new(10)
      described_class.wrappable?(thing).should be_true
    end
  end

  describe ".wrap" do
    context "for actor" do
      it "returns actor" do
        actor = described_class.wrap(subject)
        actor.should be_instance_of(described_class)
        actor.should be(subject)
      end
    end

    context "for other thing" do
      it "returns actor" do
        thing = Struct.new(:id).new('1')
        actor = described_class.wrap(thing)
        actor.should be_instance_of(described_class)
      end
    end
  end

  it "initializes with thing that responds to id" do
    thing = Struct.new(:id).new('1')
    actor = described_class.new(thing)
    actor.value.should eq('1')
  end

  it "raises error when initialized with nil" do
    expect {
      described_class.new(nil)
    }.to raise_error(ArgumentError)
  end

  it "converts id to string" do
    thing = Struct.new(:id).new(2)
    actor = described_class.new(thing)
    actor.value.should eq('2')
  end

  it "proxies everything to thing" do
    thing = thing_class.new(10)
    actor = described_class.new(thing)
    actor.admin?.should be_true
  end

  describe "#respond_to?" do
    it "returns true if responds to method" do
      thing = Struct.new(:id).new('1')
      actor = described_class.new(thing)
      actor.respond_to?(:value).should be_true
    end

    it "returns true if thing responds to method" do
      thing = thing_class.new(10)
      actor = described_class.new(thing)
      actor.respond_to?(:admin?).should be_true
    end

    it "returns false if does not respond to method and thing does not respond to method" do
      thing = Struct.new(:id).new(10)
      actor = described_class.new(thing)
      actor.respond_to?(:frankenstein).should be_false<commit_msg>Use thing class instead of struct in actor spec.<commit_after>require 'helper'
require 'flipper/types/actor'

describe Flipper::Types::Actor do
  subject {
    thing = thing_class.new('2')
    described_class.new(thing)
  }

  let(:thing_class) {
    Class.new {
      attr_reader :id

      def initialize(identifier)
        @id = id
      end

      def admin?
        true
      end
    }
  }

  describe ".wrappable?" do
    it "returns true if actor" do
      thing = thing_class.new('1')
      actor = described_class.new(thing)
      described_class.wrappable?(actor).should be_true
    end

    it "returns true if responds to id" do
      thing = thing_class.new(10)
      described_class.wrappable?(thing).should be_true
    end
  end

  describe ".wrap" do
    context "for actor" do
      it "returns actor" do
        actor = described_class.wrap(subject)
        actor.should be_instance_of(described_class)
        actor.should be(subject)
      end
    end

    context "for other thing" do
      it "returns actor" do
        thing = thing_class.new('1')
        actor = described_class.wrap(thing)
        actor.should be_instance_of(described_class)
      end
    end
  end

  it "initializes with thing that responds to id" do
    thing = thing_class.new('1')
    actor = described_class.new(thing)
    actor.value.should eq('1')
  end

  it "raises error when initialized with nil" do
    expect {
      described_class.new(nil)
    }.to raise_error(ArgumentError)
  end

  it "converts id to string" do
    thing = thing_class.new(2)
    actor = described_class.new(thing)
    actor.value.should eq('2')
  end

  it "proxies everything to thing" do
    thing = thing_class.new(10)
    actor = described_class.new(thing)
    actor.admin?.should be_true
  end

  describe "#respond_to?" do
    it "returns true if responds to method" do
      thing = thing_class.new('1')
      actor = described_class.new(thing)
      actor.respond_to?(:value).should be_true
    end

    it "returns true if thing responds to method" do
      thing = thing_class.new(10)
      actor = described_class.new(thing)
      actor.respond_to?(:admin?).should be_true
    end

    it "returns false if does not respond to method and thing does not respond to method" do
      thing = thing_class.new(10)
      actor = described_class.new(thing)
      actor.respond_to?(:frankenstein).should be_false
{'fraction_non_alphanumeric': 0.09705698184095178, 'fraction_numerical': 0.006679190148194531, 'mean_word_length': 2.669218989280245, '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': '2341803', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1488, 'n_words': 413}