<commit_before>module Remarkable
  module ActiveRecord
    module Matchers
      class HaveScopeMatcher < Remarkable::ActiveRecord::Base #:nodoc:
        arguments :scope_name
        assertions :is_scope?, :options_match?

        optionals :with, :splat => true
        
        # Chained scopes taken from: http://m.onkey.org/2010/1/22/active-record-query-interface
        optionals :where, :having, :select, :group, :order, :limit, :offset, :joins, :includes, :lock, :readonly, :from

        protected

          def is_scope?
            @scope_object = if @options.key?(:with)
              @options[:with] = [ @options[:with] ] unless Array === @options[:with]
              subject_class.send(@scope_name, *@options[:with])
            else
              subject_class.send(@scope_name)
            end

            @scope_object.class == ::ActiveRecord::Relation && @scope_object.arel 
          end

          def options_match?
            @options.empty? || @scope_object.arel == arel(subject_class, @options.except(:with))
          end

          def interpolation_options
            { 
              :options => (subject_class.respond_to?(:scoped) ? arel(subject_class, @options.except(:with)).to_sql : '{}'),
              :actual  => (@scope_object ? @scope_object.arel.to_sql : '{}')
            }
          end

        private
          def arel(model, scopes = nil)
            return model.scoped unless scopes
            scopes.inject(model.scoped) do |chain, (cond, option)|
              chain.send(cond, option)
            end.arel
          end

      end<commit_msg>[SCOPES] HaveScopeMatcher should compare sql instead of real object [fixed issue #27]<commit_after>module Remarkable
  module ActiveRecord
    module Matchers
      class HaveScopeMatcher < Remarkable::ActiveRecord::Base #:nodoc:
        arguments :scope_name
        assertions :is_scope?, :options_match?

        optionals :with, :splat => true
        
        # Chained scopes taken from: http://m.onkey.org/2010/1/22/active-record-query-interface
        optionals :where, :having, :select, :group, :order, :limit, :offset, :joins, :includes, :lock, :readonly, :from

        protected

          def is_scope?
            @scope_object = if @options.key?(:with)
              @options[:with] = [ @options[:with] ] unless Array === @options[:with]
              subject_class.send(@scope_name, *@options[:with])
            else
              subject_class.send(@scope_name)
            end

            @scope_object.class == ::ActiveRecord::Relation && @scope_object.arel 
          end
          
          def options_match?
            @options.empty? || @scope_object.arel.to_sql == arel(subject_class, @options.except(:with)).to_sql
          end

          def interpolation_options
            { 
              :options => (subject_class.respond_to?(:scoped) ? arel(subject_class, @options.except(:with)).to_sql : '{}'),
              :actual  => (@scope_object ? @scope_object.arel.to_sql : '{}')
            }
          end

        private
          def arel(model, scopes = nil)
            return model.scoped unless scopes
            scopes.inject(model.scoped) do |chain, (cond, option)|
              chain.send(cond, option)
            end.arel
          end

      end
{'fraction_non_alphanumeric': 0.11930783242258652, 'fraction_numerical': 0.004857316332726169, 'mean_word_length': 2.0852059925093633, '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': '5714892', 'n_tokens_mistral': 956, 'n_tokens_neox': 915, 'n_words': 196}