Skip to content
This repository has been archived by the owner on Aug 17, 2017. It is now read-only.

Add very basic initializer to enforce system wide #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/generators/rails/strong_parameters_initializer_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Rails
module Generators
class StrongParametersInitializerGenerator < Rails::Generators::Base
desc "Creates an initializer file to enforce strong parameters on all ActiveRecord models"

def create_initializer_file
create_file "config/initializers/strong_parameters.rb", initializer_content
end

def initializer_content
"ActiveRecord::Base.send(:include, ActiveModel::ForbiddenAttributesProtection)\n"
end
end
end
end
18 changes: 18 additions & 0 deletions test/initializer_generator_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'rails/generators/test_case'
require 'generators/rails/strong_parameters_initializer_generator'

class StrongParametersInitializerGeneratorTest < Rails::Generators::TestCase
tests Rails::Generators::StrongParametersInitializerGenerator
destination File.expand_path("../tmp", File.dirname(__FILE__))
setup :prepare_destination

def test_initializer_content
Rails.stubs(:application).returns(nil)
run_generator

assert_file "config/initializers/strong_parameters.rb" do |content|
init_code = 'ActiveRecord::Base.send(:include, ActiveModel::ForbiddenAttributesProtection)'
assert_match init_code, content
end
end
end