Sha256: 7e5a1cd8c511ba2bef23c44ef2af32757a3be041189081549671b7dc157dccdc

Contents?: true

Size: 1.66 KB

Versions: 11

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'

module RailsBestPractices
  module Reviews
    describe DefaultScopeIsEvilReview do
      let(:runner) { Core::Runner.new(reviews: DefaultScopeIsEvilReview.new) }

      it "should detect default_scope with -> syntax" do
        content = <<-EOF
        class User < ActiveRecord::Base
          default_scope -> { order('created_at desc') }
        end
        EOF
        runner.review('app/models/user.rb', content)
        expect(runner.errors.size).to eq(1)
        expect(runner.errors[0].to_s).to eq("app/models/user.rb:2 - default_scope is evil")
      end

      it "should detect default_scope with old syntax" do
        content = <<-EOF
        class User < ActiveRecord::Base
          default_scope order('created_at desc')
        end
        EOF
        runner.review('app/models/user.rb', content)
        expect(runner.errors.size).to eq(1)
        expect(runner.errors[0].to_s).to eq("app/models/user.rb:2 - default_scope is evil")
      end

      it "should not detect default_scope" do
        content = <<-EOF
        class User < ActiveRecord::Base
          scope :default, -> { order('created_at desc') }
        end
        EOF
        runner.review('app/models/user.rb', content)
        expect(runner.errors.size).to eq(0)
      end

      it "should not check ignored files" do
        runner = Core::Runner.new(reviews: DefaultScopeIsEvilReview.new(ignored_files: /user/))
        content = <<-EOF
        class User < ActiveRecord::Base
          default_scope -> { order('created_at desc') }
        end
        EOF
        runner.review('app/models/user.rb', content)
        expect(runner.errors.size).to eq(0)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rails_best_practices-1.19.0 spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb
rails_best_practices-1.18.1 spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb
rails_best_practices-1.18.0 spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb
rails_best_practices-1.17.0 spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb
rails_best_practices-1.16.0 spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb
rails_best_practices-1.15.7 spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb
rails_best_practices-1.15.6 spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb
rails_best_practices-1.15.4 spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb
rails_best_practices-1.15.3 spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb
rails_best_practices-1.15.2 spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb
rails_best_practices-1.15.1 spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb