attr_initializable 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -1
- data/Rakefile +8 -3
- data/lib/attr_initializable/version.rb +2 -1
- data/lib/attr_initializable.rb +15 -6
- data/test/{dummy → dummy-rails3}/Rakefile +0 -0
- data/test/{dummy → dummy-rails3}/app/assets/javascripts/application.js +0 -0
- data/test/{dummy → dummy-rails3}/app/assets/stylesheets/application.css +0 -0
- data/test/{dummy → dummy-rails3}/app/controllers/application_controller.rb +0 -0
- data/test/{dummy → dummy-rails3}/app/helpers/application_helper.rb +0 -0
- data/test/{dummy → dummy-rails3}/app/models/manufacturer.rb +0 -0
- data/test/{dummy → dummy-rails3}/app/models/widget.rb +0 -0
- data/test/{dummy → dummy-rails3}/app/views/layouts/application.html.erb +0 -0
- data/test/{dummy → dummy-rails3}/config/application.rb +0 -0
- data/test/{dummy → dummy-rails3}/config/boot.rb +0 -0
- data/test/{dummy → dummy-rails3}/config/database.yml +0 -0
- data/test/{dummy → dummy-rails3}/config/environment.rb +0 -0
- data/test/{dummy → dummy-rails3}/config/environments/development.rb +0 -0
- data/test/{dummy → dummy-rails3}/config/environments/production.rb +0 -0
- data/test/{dummy → dummy-rails3}/config/environments/test.rb +0 -0
- data/test/{dummy → dummy-rails3}/config/initializers/backtrace_silencers.rb +0 -0
- data/test/{dummy → dummy-rails3}/config/initializers/inflections.rb +0 -0
- data/test/{dummy → dummy-rails3}/config/initializers/mime_types.rb +0 -0
- data/test/{dummy → dummy-rails3}/config/initializers/secret_token.rb +0 -0
- data/test/{dummy → dummy-rails3}/config/initializers/session_store.rb +0 -0
- data/test/{dummy → dummy-rails3}/config/initializers/wrap_parameters.rb +0 -0
- data/test/{dummy → dummy-rails3}/config/locales/en.yml +0 -0
- data/test/{dummy → dummy-rails3}/config/routes.rb +0 -0
- data/test/{dummy → dummy-rails3}/config.ru +0 -0
- data/test/{dummy → dummy-rails3}/db/migrate/20131027192625_create_manufacturers.rb +0 -0
- data/test/{dummy → dummy-rails3}/db/migrate/20131027192834_create_widgets.rb +0 -0
- data/test/{dummy → dummy-rails3}/db/schema.rb +0 -0
- data/test/{dummy → dummy-rails3}/db/test.sqlite3 +0 -0
- data/test/dummy-rails3/log/test.log +1169 -0
- data/test/{dummy → dummy-rails3}/public/404.html +0 -0
- data/test/{dummy → dummy-rails3}/public/422.html +0 -0
- data/test/{dummy → dummy-rails3}/public/500.html +0 -0
- data/test/{dummy → dummy-rails3}/public/favicon.ico +0 -0
- data/test/{dummy → dummy-rails3}/script/rails +0 -0
- data/test/dummy-rails4/Rakefile +6 -0
- data/test/dummy-rails4/app/assets/javascripts/application.js +16 -0
- data/test/dummy-rails4/app/assets/stylesheets/application.css +13 -0
- data/test/dummy-rails4/app/controllers/application_controller.rb +5 -0
- data/test/dummy-rails4/app/helpers/application_helper.rb +2 -0
- data/test/dummy-rails4/app/models/manufacturer.rb +3 -0
- data/test/dummy-rails4/app/models/widget.rb +7 -0
- data/test/dummy-rails4/app/views/layouts/application.html.erb +14 -0
- data/test/dummy-rails4/bin/bundle +3 -0
- data/test/dummy-rails4/bin/rails +4 -0
- data/test/dummy-rails4/bin/rake +4 -0
- data/test/dummy-rails4/config/application.rb +27 -0
- data/test/dummy-rails4/config/boot.rb +4 -0
- data/test/dummy-rails4/config/database.yml +25 -0
- data/test/dummy-rails4/config/environment.rb +5 -0
- data/test/dummy-rails4/config/environments/development.rb +29 -0
- data/test/dummy-rails4/config/environments/production.rb +80 -0
- data/test/dummy-rails4/config/environments/test.rb +36 -0
- data/test/dummy-rails4/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy-rails4/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy-rails4/config/initializers/inflections.rb +16 -0
- data/test/dummy-rails4/config/initializers/mime_types.rb +5 -0
- data/test/dummy-rails4/config/initializers/secret_token.rb +12 -0
- data/test/dummy-rails4/config/initializers/session_store.rb +3 -0
- data/test/dummy-rails4/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy-rails4/config/locales/en.yml +23 -0
- data/test/dummy-rails4/config/routes.rb +56 -0
- data/test/dummy-rails4/config.ru +4 -0
- data/test/dummy-rails4/db/migrate/20131027192625_create_manufacturers.rb +9 -0
- data/test/dummy-rails4/db/migrate/20131027192834_create_widgets.rb +11 -0
- data/test/dummy-rails4/db/schema.rb +28 -0
- data/test/dummy-rails4/db/seeds.rb +7 -0
- data/test/{dummy/db/development.sqlite3 → dummy-rails4/db/test.sqlite3} +0 -0
- data/test/dummy-rails4/log/development.log +14 -0
- data/test/dummy-rails4/log/test.log +706 -0
- data/test/dummy-rails4/public/404.html +58 -0
- data/test/dummy-rails4/public/422.html +58 -0
- data/test/dummy-rails4/public/500.html +57 -0
- data/test/dummy-rails4/public/favicon.ico +0 -0
- data/test/dummy-rails4/public/robots.txt +5 -0
- data/test/test_helper.rb +12 -4
- data/test/test_utils.rb +27 -0
- metadata +154 -94
- data/test/dummy/README.rdoc +0 -261
- data/test/dummy/log/development.log +0 -28
- data/test/dummy/log/test.log +0 -690
data/README.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
# attr_initializable
|
1
|
+
# `attr_initializable`
|
2
|
+
|
3
|
+
[![Install gem](https://badge.fury.io/rb/attr_initializable.png)](https://rubygems.org/gems/attr_initializable)
|
4
|
+
[![Build status](https://travis-ci.org/rcook/attr_initializable.png)](https://travis-ci.org/rcook/attr_initializable)
|
5
|
+
[![Coverage status](https://coveralls.io/repos/rcook/attr_initializable/badge.png?branch=master)](https://coveralls.io/r/rcook/attr_initializable)
|
2
6
|
|
3
7
|
Rails plugin that provides `attr_initializable` helper to declare read-only attributes that can be mass-assigned at model creation time
|
4
8
|
|
data/Rakefile
CHANGED
@@ -12,6 +12,10 @@ rescue LoadError
|
|
12
12
|
RDoc::Task = Rake::RDocTask
|
13
13
|
end
|
14
14
|
|
15
|
+
require File.expand_path('../test/test_utils', __FILE__)
|
16
|
+
|
17
|
+
puts "Testing against Rails #{TestUtils.rails_version} with dummy application in #{TestUtils.dummy_app_dir}"
|
18
|
+
|
15
19
|
RDoc::Task.new(:rdoc) do |rdoc|
|
16
20
|
rdoc.rdoc_dir = 'rdoc'
|
17
21
|
rdoc.title = 'AttrInitializable'
|
@@ -20,9 +24,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
20
24
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
25
|
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
27
|
Bundler::GemHelper.install_tasks
|
27
28
|
|
28
29
|
require 'rake/testtask'
|
@@ -34,5 +35,9 @@ Rake::TestTask.new(:test) do |t|
|
|
34
35
|
t.verbose = false
|
35
36
|
end
|
36
37
|
|
38
|
+
task :test_db_reset do |t|
|
39
|
+
sh "cd test/#{TestUtils.dummy_app_dir}/ && RAILS_ENV=test bundle exec rake db:reset"
|
40
|
+
end
|
37
41
|
|
38
42
|
task :default => :test
|
43
|
+
|
data/lib/attr_initializable.rb
CHANGED
@@ -3,6 +3,16 @@ module AttrInitializable
|
|
3
3
|
|
4
4
|
module ClassMethods
|
5
5
|
def attr_initializable(attributes, options = {})
|
6
|
+
unless respond_to?(:protected_attributes)
|
7
|
+
raise RuntimeError.new('`attr_initializable` relies on `attr_accessible`. ' \
|
8
|
+
'Please add `protected_attributes` to your Gemfile to use `attr_initializable`.')
|
9
|
+
end
|
10
|
+
|
11
|
+
unless Rails.configuration.active_record.mass_assignment_sanitizer == :strict
|
12
|
+
logger.warn "WARNING: Running with strict mass assignment sanitizer is recommended.\n" \
|
13
|
+
"Please add config.active_record.mass_assignment_sanitizer = :strict to config/application.rb.\n"
|
14
|
+
end
|
15
|
+
|
6
16
|
role = options.delete(:as) || :default
|
7
17
|
initializable_attributes[role] ||= []
|
8
18
|
initializable_attributes[role] += Array(attributes)
|
@@ -14,12 +24,11 @@ module AttrInitializable
|
|
14
24
|
end
|
15
25
|
|
16
26
|
included do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
accessible_attributes
|
27
|
+
def mass_assignment_authorizer(role = :default)
|
28
|
+
authorizer = super
|
29
|
+
authorizer += Array(self.class.initializable_attributes[role]) unless persisted?
|
30
|
+
authorizer
|
31
|
+
end
|
23
32
|
end
|
24
33
|
end
|
25
34
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|