ledermann-rails-settings 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/Changelog.md +22 -0
- data/README.md +9 -11
- data/ci/Gemfile.rails-3.1.x +1 -0
- data/ci/Gemfile.rails-3.2.x +1 -0
- data/lib/generators/rails_settings/migration/templates/migration.rb +1 -1
- data/lib/rails-settings/version.rb +1 -1
- data/rails-settings.gemspec +2 -1
- data/spec/database.yml +8 -0
- data/spec/setting_object_spec.rb +18 -5
- data/spec/spec_helper.rb +13 -5
- data/spec/support/query_counter.rb +1 -1
- metadata +21 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e95ccf650df85deaa3086b12f49c7cf6d10cd13
|
4
|
+
data.tar.gz: 4d2a68fa5cda6250f29440ec426bef760f65a72f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6dd9ded21d964802a6a20b01b38a5d9361ce2b8d6d6ac960886504a1db17a3e562b34325351ed7c9684b33f57c872a1b48908e079d199889722401805d33135
|
7
|
+
data.tar.gz: 1cdd6dbf6085d40544b52678ccaeea7cab94dbb6b907f3a10371cac806ea8263bfef230ab393da421b81692a338861dfdc1219e5c11c1fe649b9cc95f9bb52ac
|
data/.travis.yml
CHANGED
data/Changelog.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
Version 2.0.2 (2013-03-17)
|
2
|
+
|
3
|
+
- Changed database schema to allow NULL for column `value` to fix serialization
|
4
|
+
bug with MySQL. Thanks to @steventen for pointing this out in issue #31.
|
5
|
+
|
6
|
+
IMPORTANT: The migration generator of version 2.0.0 and 2.0.1 was broken. If
|
7
|
+
you use MySQL it's required to update your database schema like
|
8
|
+
this:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
class FixSettings < ActiveRecord::Migration
|
12
|
+
def up
|
13
|
+
change_column :settings, :value, :text, :null => true
|
14
|
+
end
|
15
|
+
|
16
|
+
def down
|
17
|
+
change_column :settings, :value, :text, :null => false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
|
1
23
|
Version 2.0.1 (2013-03-08)
|
2
24
|
|
3
25
|
- Added mass assignment security by protecting all regular attributes
|
data/README.md
CHANGED
@@ -3,14 +3,12 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/ledermann/rails-settings.png?branch=master)](https://travis-ci.org/ledermann/rails-settings)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/ledermann/rails-settings.png)](https://codeclimate.com/github/ledermann/rails-settings)
|
5
5
|
|
6
|
-
Ruby gem to handle settings for ActiveRecord
|
6
|
+
Ruby gem to handle settings for ActiveRecord instances by storing them as serialized Hash in a separate database table. Namespaces and defaults included.
|
7
7
|
|
8
|
-
**BEWARE: This is version 2 which is a complete rewrite and NOT compatible with version 1.x**
|
9
8
|
|
9
|
+
## Usage
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
### Defining settings
|
11
|
+
### Define settings
|
14
12
|
|
15
13
|
```ruby
|
16
14
|
class User < ActiveRecord::Base
|
@@ -98,13 +96,13 @@ User.without_settings_for(:calendar)
|
|
98
96
|
|
99
97
|
## Requirements
|
100
98
|
|
101
|
-
|
102
|
-
|
99
|
+
* Ruby 1.8.7, 1.9.3 or 2.0.0
|
100
|
+
* Rails 3.1.x or 3.2.x
|
103
101
|
|
104
102
|
|
105
103
|
## Installation
|
106
104
|
|
107
|
-
Include the gem in your Gemfile:
|
105
|
+
Include the gem in your Gemfile und run `bundle` to install it:
|
108
106
|
|
109
107
|
```ruby
|
110
108
|
gem 'ledermann-rails-settings', :require => 'rails-settings'
|
@@ -119,8 +117,7 @@ rake db:migrate
|
|
119
117
|
|
120
118
|
## Compatibility
|
121
119
|
|
122
|
-
Version 2 is a complete rewrite and has a new DSL, so it's **not** compatible with Version 1. But the database schema is unchanged, so you can use the
|
123
|
-
In addition, Rails 2.3 is not supported anymore.
|
120
|
+
Version 2 is a complete rewrite and has a new DSL, so it's **not** compatible with Version 1. In addition, Rails 2.3 is not supported anymore. But the database schema is unchanged, so you can continue to use the data created by 1.x, no conversion is needed.
|
124
121
|
|
125
122
|
If you don't want to upgrade, you find the old version in the [1.x](https://github.com/ledermann/rails-settings/commits/1.x) branch. But don't expect any updates there.
|
126
123
|
|
@@ -128,6 +125,7 @@ If you don't want to upgrade, you find the old version in the [1.x](https://gith
|
|
128
125
|
## License
|
129
126
|
|
130
127
|
MIT License
|
131
|
-
|
128
|
+
|
129
|
+
Copyright (c) 2013 [Georg Ledermann](http://www.georg-ledermann.de)
|
132
130
|
|
133
131
|
This gem is a complete rewrite of [rails-settings](https://github.com/Squeegy/rails-settings) by [Alex Wayne](https://github.com/Squeegy)
|
data/ci/Gemfile.rails-3.1.x
CHANGED
data/ci/Gemfile.rails-3.2.x
CHANGED
data/rails-settings.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.authors = ['Georg Ledermann']
|
10
10
|
gem.email = ['mail@georg-ledermann.de']
|
11
11
|
gem.description = %q{Settings gem for Ruby on Rails}
|
12
|
-
gem.summary = %q{
|
12
|
+
gem.summary = %q{Ruby gem to handle settings for ActiveRecord instances by storing them as serialized Hash in a separate database table. Namespaces and defaults included.}
|
13
13
|
gem.homepage = 'https://github.com/ledermann/rails-settings'
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
@@ -21,5 +21,6 @@ Gem::Specification.new do |gem|
|
|
21
21
|
|
22
22
|
gem.add_development_dependency 'rake', '~> 10.0'
|
23
23
|
gem.add_development_dependency 'sqlite3', '~> 1.3'
|
24
|
+
gem.add_development_dependency 'mysql2', '~> 0.3.11'
|
24
25
|
gem.add_development_dependency 'rspec', '~> 2.13'
|
25
26
|
end
|
data/spec/database.yml
ADDED
data/spec/setting_object_spec.rb
CHANGED
@@ -5,6 +5,12 @@ describe RailsSettings::SettingObject do
|
|
5
5
|
let(:new_setting_object) { user.setting_objects.build({ :var => 'dashboard'}, :without_protection => true) }
|
6
6
|
let(:saved_setting_object) { user.setting_objects.create!({ :var => 'dashboard', :value => { 'theme' => 'pink', 'filter' => true}}, :without_protection => true) }
|
7
7
|
|
8
|
+
describe "serialization" do
|
9
|
+
it "should have a hash default" do
|
10
|
+
RailsSettings::SettingObject.new.value.should == {}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
8
14
|
describe "Getter and Setter" do
|
9
15
|
context "on unsaved settings" do
|
10
16
|
it "should respond to setters" do
|
@@ -40,11 +46,18 @@ describe RailsSettings::SettingObject do
|
|
40
46
|
new_setting_object.filter.should eq(false)
|
41
47
|
end
|
42
48
|
|
43
|
-
it "should store to value hash" do
|
44
|
-
new_setting_object.
|
45
|
-
new_setting_object.
|
46
|
-
|
47
|
-
new_setting_object.
|
49
|
+
it "should store different objects to value hash" do
|
50
|
+
new_setting_object.integer = 42
|
51
|
+
new_setting_object.float = 1.234
|
52
|
+
new_setting_object.string = 'Hello, World!'
|
53
|
+
new_setting_object.array = [ 1,2,3 ]
|
54
|
+
new_setting_object.symbol = :foo
|
55
|
+
|
56
|
+
new_setting_object.value.should eq('integer' => 42,
|
57
|
+
'float' => 1.234,
|
58
|
+
'string' => 'Hello, World!',
|
59
|
+
'array' => [ 1,2,3 ],
|
60
|
+
'symbol' => :foo)
|
48
61
|
end
|
49
62
|
|
50
63
|
it "should set and return attributes" do
|
data/spec/spec_helper.rb
CHANGED
@@ -23,9 +23,6 @@ end
|
|
23
23
|
require 'active_record'
|
24
24
|
require 'rails-settings'
|
25
25
|
|
26
|
-
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
27
|
-
ActiveRecord::Migration.verbose = false
|
28
|
-
|
29
26
|
class User < ActiveRecord::Base
|
30
27
|
has_settings do |s|
|
31
28
|
s.key :dashboard, :defaults => { :theme => 'blue', :view => 'monthly', :filter => false }
|
@@ -56,10 +53,22 @@ class ProjectSettingObject < RailsSettings::SettingObject
|
|
56
53
|
end
|
57
54
|
|
58
55
|
def setup_db
|
56
|
+
ActiveRecord::Base.configurations = YAML.load_file(File.dirname(__FILE__) + '/database.yml')
|
57
|
+
db_name = ENV['DB'] || 'sqlite'
|
58
|
+
ActiveRecord::Base.establish_connection(db_name)
|
59
|
+
|
60
|
+
ActiveRecord::Migration.verbose = false
|
61
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
62
|
+
next if table == 'schema_migrations'
|
63
|
+
ActiveRecord::Base.connection.execute("DROP TABLE #{table}")
|
64
|
+
end
|
65
|
+
|
66
|
+
puts "Testing on #{db_name} with ActiveRecord #{ActiveRecord::VERSION::STRING}"
|
67
|
+
|
59
68
|
ActiveRecord::Schema.define(:version => 1) do
|
60
69
|
create_table :settings do |t|
|
61
70
|
t.string :var, :null => false
|
62
|
-
t.text :value
|
71
|
+
t.text :value
|
63
72
|
t.references :target, :null => false, :polymorphic => true
|
64
73
|
t.timestamps
|
65
74
|
end
|
@@ -86,5 +95,4 @@ def clear_db
|
|
86
95
|
RailsSettings::SettingObject.delete_all
|
87
96
|
end
|
88
97
|
|
89
|
-
puts "Testing with ActiveRecord #{ActiveRecord::VERSION::STRING}"
|
90
98
|
setup_db
|
@@ -11,7 +11,7 @@ module ActiveRecord
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def callback(name, start, finish, message_id, values)
|
14
|
-
@query_count += 1 unless %w(CACHE SCHEMA).include?(values[:name]) || values[:sql]
|
14
|
+
@query_count += 1 unless %w(CACHE SCHEMA).include?(values[:name]) || values[:sql] =~ /^begin/i || values[:sql] =~ /^commit/i
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ledermann-rails-settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Ledermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mysql2
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.3.11
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.3.11
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,6 +106,7 @@ files:
|
|
92
106
|
- lib/rails-settings/version.rb
|
93
107
|
- rails-settings.gemspec
|
94
108
|
- spec/configuration_spec.rb
|
109
|
+
- spec/database.yml
|
95
110
|
- spec/queries_spec.rb
|
96
111
|
- spec/scopes_spec.rb
|
97
112
|
- spec/serialize_spec.rb
|
@@ -119,13 +134,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
134
|
version: '0'
|
120
135
|
requirements: []
|
121
136
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.0.
|
137
|
+
rubygems_version: 2.0.3
|
123
138
|
signing_key:
|
124
139
|
specification_version: 4
|
125
|
-
summary:
|
126
|
-
Hash in a separate database table.
|
140
|
+
summary: Ruby gem to handle settings for ActiveRecord instances by storing them as
|
141
|
+
serialized Hash in a separate database table. Namespaces and defaults included.
|
127
142
|
test_files:
|
128
143
|
- spec/configuration_spec.rb
|
144
|
+
- spec/database.yml
|
129
145
|
- spec/queries_spec.rb
|
130
146
|
- spec/scopes_spec.rb
|
131
147
|
- spec/serialize_spec.rb
|