<commit_before>module ModelJanitor
  module Shoulda
    module Matchers
      
      def is_attribute_sanitized(attr_name, mode)
        AttributeSanitizedMatcher.new(attr_name, mode)
      end
      
      class AttributeSanitizedMatcher
        def initialize(attr_name, mode)
          @attr_name = attr_name
          @mode = mode
        end
        
        def matches?(subject)
          @subject = subject.new
          @subject[@attr_name] = "<b>Lorem</b> <div>ipsum</div>"
          @subject.save_with_validation(false)
          if strip_tags_mode?
            @subject[@attr_name] == "Lorem ipsum"
          else
            @subject[@attr_name] == "<b>Lorem</b> ipsum"
          end
        end
        
        def failure_message
          "Should " + mode_message
        end
        
        def negative_failure_message
          "Should not " + mode_message
        end
        
        def description
          mode_message
        end
        
        private
        
        def strip_tags_mode?
          @mode == :strip_tags
        end
        
        def mode_message
          if strip_tags_mode?
            "strip tags from the attribute `#{@attr_name}'"
          else
            "sanitize the attribute `#{@attr_name}'"
          end
        end
      end

    end
  end
end<commit_msg>fixed attribute accessors in shoulda matcher<commit_after>module ModelJanitor
  module Shoulda
    module Matchers
      
      def is_attribute_sanitized(attr_name, mode)
        AttributeSanitizedMatcher.new(attr_name, mode)
      end
      
      class AttributeSanitizedMatcher
        def initialize(attr_name, mode)
          @attr_name = attr_name
          @mode = mode
        end
        
        def matches?(subject)
          @subject = subject.new
          @subject.send("#{@attr_name}=", "<a href=\"http://lala.com/\">Lorem</a> <div>ipsum</div>")
          @subject.save_with_validation(false)
          if strip_tags_mode?
            @subject.send(@attr_name) == "Lorem ipsum"
          else
            @subject.send(@attr_name) == "<a href=\"http://lala.com/\">Lorem</a> ipsum"
          end
        end
        
        def failure_message
          "Should #{mode_message}, got '#{@subject.send(@attr_name)}'"
        end
        
        def negative_failure_message
          "Should not #{mode_message}, got '#{@subject.send(@attr_name)}'"
        end
        
        def description
          mode_message
        end
        
        private
        
        def strip_tags_mode?
          @mode == :strip_tags
        end
        
        def mode_message
          if strip_tags_mode?
            "strip tags from the attribute `#{@attr_name}'"
          else
            "sanitize the attribute `#{@attr_name}'"
          end
        end
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.08620078041858815, 'fraction_numerical': 0.0, 'mean_word_length': 1.558983666061706, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4658850', 'n_tokens_mistral': 791, 'n_tokens_neox': 798, 'n_words': 176}