Sha256: ecdf2e582fdecc909fd13bd7b0dbffc9ada4ebe1d83b831ca1c2f39d7fb38337

Contents?: true

Size: 1.93 KB

Versions: 1

Compression:

Stored size: 1.93 KB

Contents

require 'spec_helper'

describe RailsBestPractices::Reviews::ProtectMassAssignmentReview do
  let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::ProtectMassAssignmentReview.new) }

  it "should protect mass assignment" do
    content =<<-EOF
    class User < ActiveRecord::Base
    end
    EOF
    runner.review('app/models/user.rb', content)
    runner.should have(1).errors
    runner.errors[0].to_s.should == "app/models/user.rb:1 - protect mass assignment"
  end

  it "should not protect mass assignment with attr_accessible" do
    content =<<-EOF
    class User < ActiveRecord::Base
      attr_accessible :email, :password, :password_confirmation
    end
    EOF
    runner.review('app/models/user.rb', content)
    runner.should have(0).errors
  end

  it "should not protect mass assignment with attr_protected" do
    content =<<-EOF
    class User < ActiveRecord::Base
      attr_protected :role
    end
    EOF
    runner.review('app/models/user.rb', content)
    runner.should have(0).errors
  end

  it "should not protect mass assignment if using devise" do
    content =<<-EOF
    class User < ActiveRecord::Base
      devise :database_authenticatable, :registerable, :confirmable, :recoverable, :stretches => 20
    end
    EOF
    runner.review('app/models/user.rb', content)
    runner.should have(0).errors
  end

  it "should not protect mass assignment if using authlogic with configuration" do
    content =<<-EOF
    class User < ActiveRecord::Base
      acts_as_authentic do |c|
        c.my_config_option = my_value
      end
    end
    EOF
    runner.review('app/models/user.rb', content)
    runner.should have(0).errors
  end

  it "should not protect mass assignment if using authlogic without configuration" do
    content =<<-EOF
    class User < ActiveRecord::Base
      acts_as_authentic
    end
    EOF
    runner.review('app/models/user.rb', content)
    runner.should have(0).errors
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_best_practices-1.9.0 spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb