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