<commit_before>require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'

describe DataMapper::Voyeur do
  before :all do
    class Adam
      include DataMapper::Resource
      
      property :id, Integer, :serial => true
      property :name, String
      attr_accessor :done
      
      def falling?
        @falling
      end
      
      def dig_a_hole_to_china
        @done = true
      end
      
      def drink
        @happy = true
      end
      
      def happy?
        @happy
      end
      
    end
    Adam.auto_migrate!
    
    class Beer
      include DataMapper::Resource
      
      property :id, Integer, :serial => true
      property :name, String
      
      def drink
        @empty = true
      end
      
      def empty?
        @empty
      end
      
    end
    Beer.auto_migrate!
    
    class AdamVoyeur
      include DataMapper::Voyeur
      
      peep Adam
      
      before :save do
        @falling = true
      end
      
      before :dig_a_hole_to_china do
        throw :halt
      end
      
    end
    
    class DrinkingVoyeur
      include DataMapper::Voyeur
      
      peep Adam, Beer
      
      after :drink do
        @refrigerated = true
      end
      
    end
    
  end
    
  before(:each) do
    @adam = Adam.new
    @beer = Beer.new
  end
  
  it "should assign a callback" do
    @adam.should_not be_falling
    @adam.name = "<NAME>"
    @adam.save
    @adam.should be_falling
  end    
  
  it "should be able to trigger an abort" do
     @adam.dig_a_hole_to_china
     @adam.done.should be_nil
  end
  
  it "peep should add a class to the neighborhood watch" do
    AdamVoyeur.should have(1).neighborhood_watch
    AdamVoyeur.neighborhood_watch.first.should == Adam
  end
  
  it "peep should add more than one class to the neighborhood watch" do
    DrinkingVoyeur.should have(2).neighborhood_watch
    DrinkingVoyeur.neighborhood_watch.first.should == Adam
    DrinkingVoyeur.neighborhood_watch[1].should == Beer
  end
  
  it "should peep multiple classes with the same method name" do
    @adam.should_not be_happy
    @beer.should_not be_empty
    @adam.drink
    @beer.drink
    @adam.should be_happy
    @beer.should be_empty
  end
  
end<commit_msg>Confirming name spaced modules work in Voyeur<commit_after>require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'

describe DataMapper::Voyeur do
  before :all do
    class Adam
      include DataMapper::Resource
      
      property :id, Integer, :serial => true
      property :name, String
      attr_accessor :done
      
      def falling?
        @falling
      end
      
      def dig_a_hole_to_china
        @done = true
      end
      
      def drink
        @happy = true
      end
      
      def happy?
        @happy
      end
      
    end
    Adam.auto_migrate!
    
    module Alcohol
      class Beer
        include DataMapper::Resource
      
        property :id, Integer, :serial => true
        property :name, String
      
        def drink
          @empty = true
        end
      
        def empty?
          @empty
        end
      
      end
    end
    Alcohol::Beer.auto_migrate!

    
    class AdamVoyeur
      include DataMapper::Voyeur
      
      peep Adam
      
      before :save do
        @falling = true
      end
      
      before :dig_a_hole_to_china do
        throw :halt
      end
      
    end
    
    class DrinkingVoyeur
      include DataMapper::Voyeur
      
      peep Adam, Alcohol::Beer
      
      after :drink do
        @refrigerated = true
      end
      
    end
    
  end
    
  before(:each) do
    @adam = Adam.new
    @beer = Alcohol::Beer.new
  end
  
  it "should assign a callback" do
    @adam.should_not be_falling
    @adam.name = "<NAME>"
    @adam.save
    @adam.should be_falling
  end    
  
  it "should be able to trigger an abort" do
     @adam.dig_a_hole_to_china
     @adam.done.should be_nil
  end
  
  it "peep should add a class to the neighborhood watch" do
    AdamVoyeur.should have(1).neighborhood_watch
    AdamVoyeur.neighborhood_watch.first.should == Adam
  end
  
  it "peep should add more than one class to the neighborhood watch" do
    DrinkingVoyeur.should have(2).neighborhood_watch
    DrinkingVoyeur.neighborhood_watch.first.should == Adam
    DrinkingVoyeur.neighborhood_watch[1].should == Alcohol::Beer
  end
  
  it "should peep multiple classes with the same method name" do
    @adam.should_not be_happy
    @beer.should_not be_empty
    @adam.drink
    @beer.drink
    @adam.should be_happy
    @beer.should be_empty
  end
  
end
{'fraction_non_alphanumeric': 0.06153184165232358, 'fraction_numerical': 0.0012908777969018934, 'mean_word_length': 1.8364856619890177, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '360184', 'n_tokens_mistral': 1522, 'n_tokens_neox': 1473, 'n_words': 398}