Sha256: 9f2a91b984516ffb43bf94e06944ff019b01013c41dc137f35cc088e952a9efb

Contents?: true

Size: 1.95 KB

Versions: 36

Compression:

Stored size: 1.95 KB

Contents

require File.join(File.dirname(__FILE__) + '/../../spec_helper')

describe RailsBestPractices::Checks::KeepFindersOnTheirOwnModelCheck do
  before(:each) do
    @runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::KeepFindersOnTheirOwnModelCheck.new)
  end

  it "should keep finders on thier own model" do
    content = <<-EOF
    class Post < ActiveRecord::Base
      has_many :comments

      def find_valid_comments
        self.comment.find(:all, :conditions => { :is_spam => false }, 
                                :limit => 10)
      end
    end
    EOF
    @runner.check('app/models/post.rb', content)
    errors = @runner.errors
    errors.should_not be_empty
    errors[0].to_s.should == "app/models/post.rb:5 - keep finders on their own model"
  end

  it "should not keep finders on thier own model with self finder" do
    content = <<-EOF
    class Post < ActiveRecord::Base
      has_many :comments

      def find_valid_comments
        self.find(:all, :conditions => { :is_spam => false }, 
                                :limit => 10)
      end
    end
    EOF
    @runner.check('app/models/post.rb', content)
    errors = @runner.errors
    errors.should be_empty
  end

  it "should not keep finders on thier own model with own finder" do
    content = <<-EOF
    class Post < ActiveRecord::Base
      has_many :comments

      def find_valid_comments
        Post.find(:all, :conditions => { :is_spam => false }, 
                                :limit => 10)
      end
    end
    EOF
    @runner.check('app/models/post.rb', content)
    errors = @runner.errors
    errors.should be_empty
  end

  it "should not keep finders on thier own model without finder" do
    content = <<-EOF
    class Post < ActiveRecord::Base
      has_many :comments

      def find_valid_comments
        self.comments.destroy_all
      end
    end
    EOF
    @runner.check('app/models/post.rb', content)
    errors = @runner.errors
    errors.should be_empty
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
rails_best_practices-0.3.20 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.19 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.18 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.17 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.16 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.15 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.14 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.13 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.12 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.11 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.10 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.9 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.8 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.7 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.6 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.5 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.4 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.3 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.2 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
rails_best_practices-0.3.1 spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb