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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: acfe3a67b8daf8e9108c0ddf270e638c4310d2b1
4
- data.tar.gz: ef9c5a3a455365f5817f56f5476b12d9283d2440
3
+ metadata.gz: 1e95ccf650df85deaa3086b12f49c7cf6d10cd13
4
+ data.tar.gz: 4d2a68fa5cda6250f29440ec426bef760f65a72f
5
5
  SHA512:
6
- metadata.gz: 5fd20605f8b1dc5474b94402140baba09d08a5d59429269ebb37bc4bd5b63742088a24ed0c2ccbf6b7cb127c631fb5522b85636735a1a6b28f94853ed97b90e5
7
- data.tar.gz: 3c4f8c5f8f5732e727cf116a341d04f09e519e8e1aa13df8b94e72f3dfd532a6155a1cfa7c4af0de44ceebce271ca4e28a1e5b129008994a992362fb14de44ea
6
+ metadata.gz: b6dd9ded21d964802a6a20b01b38a5d9361ce2b8d6d6ac960886504a1db17a3e562b34325351ed7c9684b33f57c872a1b48908e079d199889722401805d33135
7
+ data.tar.gz: 1cdd6dbf6085d40544b52678ccaeea7cab94dbb6b907f3a10371cac806ea8263bfef230ab393da421b81692a338861dfdc1219e5c11c1fe649b9cc95f9bb52ac
data/.travis.yml CHANGED
@@ -6,3 +6,8 @@ rvm:
6
6
  gemfile:
7
7
  - ci/Gemfile.rails-3.1.x
8
8
  - ci/Gemfile.rails-3.2.x
9
+ env:
10
+ - DB=sqlite
11
+ - DB=mysql
12
+ before_script:
13
+ - "mysql -e 'create database rails_settings_test;' >/dev/null"
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 objects by storing them as serialized Hash in a separate database table. Optional: Defaults and Namespaces.
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
- ## Example
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
- Rails 3.1.x or 3.2.x
102
- Ruby 1.8.7, 1.9.3 or 2.0.0
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 same data after upgrading.
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
- Copyright (c) 2013 Georg Ledermann
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)
@@ -2,5 +2,6 @@ source :rubygems
2
2
 
3
3
  gem 'activerecord', '~> 3.1.0'
4
4
  gem 'sqlite3', '~> 1.3'
5
+ gem 'mysql2', '>= 0.3.6'
5
6
  gem 'rake', '~> 10.0'
6
7
  gem 'rspec', '~> 2.13'
@@ -2,5 +2,6 @@ source :rubygems
2
2
 
3
3
  gem 'activerecord', '~> 3.2.0'
4
4
  gem 'sqlite3', '~> 1.3'
5
+ gem 'mysql2', '>= 0.3.6'
5
6
  gem 'rake', '~> 10.0'
6
7
  gem 'rspec', '~> 2.13'
@@ -2,7 +2,7 @@ class RailsSettingsMigration < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :settings do |t|
4
4
  t.string :var, :null => false
5
- t.text :value, :null => false
5
+ t.text :value
6
6
  t.references :target, :null => false, :polymorphic => true
7
7
  t.timestamps
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module RailsSettings
2
- VERSION = '2.0.1'
2
+ VERSION = '2.0.2'
3
3
  end
@@ -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{Handling settings for ActiveRecord objects by storing them as serialized Hash in a separate database table. Optional: Defaults and Namespaces.}
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
@@ -0,0 +1,8 @@
1
+ sqlite:
2
+ adapter: sqlite3
3
+ database: ":memory:"
4
+ mysql:
5
+ adapter: mysql2
6
+ database: rails_settings_test
7
+ username:
8
+ encoding: utf8
@@ -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.foo = 42
45
- new_setting_object.bar = 'hello'
46
-
47
- new_setting_object.value.should eq({'foo' => 42, 'bar' => 'hello'})
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, :null => false
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] == 'begin transaction' || values[:sql] == 'commit transaction'
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.1
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-08 00:00:00.000000000 Z
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.2
137
+ rubygems_version: 2.0.3
123
138
  signing_key:
124
139
  specification_version: 4
125
- summary: 'Handling settings for ActiveRecord objects by storing them as serialized
126
- Hash in a separate database table. Optional: Defaults and Namespaces.'
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