ledermann-rails-settings 2.2.1 → 2.3.0

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: 36a283476edb425a05d5ab93dd84917961c1f7f1
4
- data.tar.gz: 2edc040a3634bba291c15467b83e34a9652ce3ad
3
+ metadata.gz: 71d258f55435ac0936befafa014944f3a3ae72da
4
+ data.tar.gz: 0f9f767391fad56c4ff44a7ff44494ad4b6c09b6
5
5
  SHA512:
6
- metadata.gz: 7175a627b62d0fcbbaa771e76a08b1c6cd5e352c65fd6e70e1c9d4cb2374f18bc03d4844b1d659319aaed75f7fc944664f392f8332f9c5183402b611b1035a8c
7
- data.tar.gz: c4823aad4b4edd91f116cbb21de4a180ef4932ad705923fa9cf56764b42fd3dd0c0eacef746218ef4bd6c6c3c1fd99db4449228721f15e95c0fb58e04c5aaa32
6
+ metadata.gz: d621905d20eab2e0962c943242286d0eb9097731f3eb4f7d23edb3102494ce774e5eaf64cff455ff2c7f49461050976f4c44b6af4550888955f39ed8d83feac6
7
+ data.tar.gz: 378399bc595e654aa79323d51cdc963b778024427713332f9c93aff0a25595146be562604299681f931fd644fbb230208c07ca7e6164ebde5b64c0d8dea9d895
data/.travis.yml CHANGED
@@ -2,11 +2,12 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - 2.1.0
5
+ - 2.1.1
6
6
  gemfile:
7
7
  - ci/Gemfile-rails-3-1
8
8
  - ci/Gemfile-rails-3-2
9
9
  - ci/Gemfile-rails-4-0
10
+ - ci/Gemfile-rails-4-1
10
11
  env:
11
12
  - DB=sqlite
12
13
  - DB=mysql
data/README.md CHANGED
@@ -5,6 +5,27 @@
5
5
 
6
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
+ ## Requirements
9
+
10
+ * Ruby 1.9.3 or newer
11
+ * Rails 3.1 or greater (including Rails 4)
12
+
13
+
14
+ ## Installation
15
+
16
+ Include the gem in your Gemfile and run `bundle` to install it:
17
+
18
+ ```ruby
19
+ gem 'ledermann-rails-settings'
20
+ ```
21
+
22
+ Generate and run the migration:
23
+
24
+ ```shell
25
+ rails g rails_settings:migration
26
+ rake db:migrate
27
+ ```
28
+
8
29
 
9
30
  ## Usage
10
31
 
@@ -76,6 +97,15 @@ user.settings(:calendar).scope
76
97
  # => 'all'
77
98
  ```
78
99
 
100
+ ### Delete settings
101
+
102
+ ```ruby
103
+ user = User.find(1)
104
+ user.settings(:dashboard).update_attributes! :theme => nil
105
+
106
+ user.settings(:dashboard).view = nil
107
+ user.settings(:dashboard).save!
108
+ ```
79
109
 
80
110
  ### Using scopes
81
111
 
@@ -94,27 +124,6 @@ User.without_settings_for(:calendar)
94
124
  ```
95
125
 
96
126
 
97
- ## Requirements
98
-
99
- * Ruby 1.9.3 or newer
100
- * Rails 3.1 or greater (including Rails 4)
101
-
102
-
103
- ## Installation
104
-
105
- Include the gem in your Gemfile and run `bundle` to install it:
106
-
107
- ```ruby
108
- gem 'ledermann-rails-settings', :require => 'rails-settings'
109
- ```
110
-
111
- Generate and run the migration:
112
-
113
- ```shell
114
- rails g rails_settings:migration
115
- rake db:migrate
116
- ```
117
-
118
127
  ## Compatibility
119
128
 
120
129
  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.
data/ci/Gemfile-rails-3-1 CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activerecord', '~> 3.1.0'
3
+ gem 'activerecord', '~> 3.1.12'
4
4
  gem 'sqlite3', '~> 1.3'
5
5
  gem 'mysql2', '>= 0.3.6'
6
6
  gem 'rake', '~> 10.0'
data/ci/Gemfile-rails-3-2 CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activerecord', '~> 3.2.0'
3
+ gem 'activerecord', '~> 3.2.17'
4
4
  gem 'sqlite3', '~> 1.3'
5
5
  gem 'mysql2', '>= 0.3.6'
6
6
  gem 'rake', '~> 10.0'
data/ci/Gemfile-rails-4-0 CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activerecord', '~> 4.0.0'
3
+ gem 'activerecord', '~> 4.0.4'
4
4
  gem 'sqlite3', '~> 1.3'
5
5
  gem 'mysql2', '>= 0.3.6'
6
6
  gem 'rake', '~> 10.0'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 4.1.0'
4
+ gem 'sqlite3', '~> 1.3'
5
+ gem 'mysql2', '>= 0.3.6'
6
+ gem 'rake', '~> 10.0'
7
+ gem 'rspec', '~> 2.13'
@@ -9,7 +9,7 @@ module RailsSettings
9
9
  source_root File.expand_path('../templates', __FILE__)
10
10
 
11
11
  def create_migration_file
12
- migration_template 'migration.rb', 'db/migrate/rails_settings_migration'
12
+ migration_template 'migration.rb', 'db/migrate/rails_settings_migration.rb'
13
13
  end
14
14
 
15
15
  def self.next_migration_number(dirname)
@@ -0,0 +1 @@
1
+ require 'rails-settings'
@@ -4,8 +4,10 @@ module RailsSettings
4
4
 
5
5
  belongs_to :target, :polymorphic => true
6
6
 
7
- validates_presence_of :var, :value, :target_type
7
+ validates_presence_of :var, :target_type
8
8
  validate do
9
+ errors.add(:value, "Invalid setting value") unless value.is_a? Hash
10
+
9
11
  unless _target_class.default_settings[var.to_sym]
10
12
  errors.add(:var, "#{var} is not defined!")
11
13
  end
@@ -1,3 +1,3 @@
1
1
  module RailsSettings
2
- VERSION = '2.2.1'
2
+ VERSION = '2.3.0'
3
3
  end
@@ -109,7 +109,7 @@ describe RailsSettings::SettingObject do
109
109
  end
110
110
 
111
111
  it 'should not save blank hash' do
112
- new_setting_object.update_attributes({}).should be_false
112
+ new_setting_object.update_attributes({}).should be_true
113
113
  end
114
114
 
115
115
  if ActiveRecord::VERSION::MAJOR < 4
@@ -39,6 +39,23 @@ describe 'Objects' do
39
39
  account.settings(:portal).value.should eq({})
40
40
  end
41
41
 
42
+ it 'should allow saving a blank value' do
43
+ account.save!
44
+ account.settings(:portal).save.should be_true
45
+ end
46
+
47
+ it 'should allow removing all values' do
48
+ account.settings(:portal).premium = true
49
+ account.settings(:portal).fee = 42.5
50
+ account.save!
51
+
52
+ account.settings(:portal).premium = nil
53
+ account.save.should be_true
54
+
55
+ account.settings(:portal).fee = nil
56
+ account.save.should be_true
57
+ end
58
+
42
59
  it 'should not add settings on saving' do
43
60
  account.save!
44
61
  RailsSettings::SettingObject.count.should eq(0)
data/spec/spec_helper.rb CHANGED
@@ -59,25 +59,14 @@ end
59
59
  def setup_db
60
60
  ActiveRecord::Base.configurations = YAML.load_file(File.dirname(__FILE__) + '/database.yml')
61
61
  db_name = ENV['DB'] || 'sqlite'
62
- ActiveRecord::Base.establish_connection(db_name)
63
-
62
+ ActiveRecord::Base.establish_connection(db_name.to_sym)
64
63
  ActiveRecord::Migration.verbose = false
65
- ActiveRecord::Base.connection.tables.each do |table|
66
- next if table == 'schema_migrations'
67
- ActiveRecord::Base.connection.execute("DROP TABLE #{table}")
68
- end
69
-
70
64
  puts "Testing on #{db_name} with ActiveRecord #{ActiveRecord::VERSION::STRING}"
71
65
 
72
- ActiveRecord::Schema.define(:version => 1) do
73
- create_table :settings do |t|
74
- t.string :var, :null => false
75
- t.text :value
76
- t.references :target, :null => false, :polymorphic => true
77
- t.timestamps
78
- end
79
- add_index :settings, [ :target_type, :target_id, :var ], :unique => true
66
+ require File.expand_path('../../lib/generators/rails_settings/migration/templates/migration.rb', __FILE__)
67
+ RailsSettingsMigration.migrate(:up)
80
68
 
69
+ ActiveRecord::Schema.define(:version => 1) do
81
70
  create_table :users do |t|
82
71
  t.string :type
83
72
  t.string :name
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.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Georg Ledermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-30 00:00:00.000000000 Z
11
+ date: 2014-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -96,8 +96,10 @@ files:
96
96
  - ci/Gemfile-rails-3-1
97
97
  - ci/Gemfile-rails-3-2
98
98
  - ci/Gemfile-rails-4-0
99
+ - ci/Gemfile-rails-4-1
99
100
  - lib/generators/rails_settings/migration/migration_generator.rb
100
101
  - lib/generators/rails_settings/migration/templates/migration.rb
102
+ - lib/ledermann-rails-settings.rb
101
103
  - lib/rails-settings.rb
102
104
  - lib/rails-settings/base.rb
103
105
  - lib/rails-settings/configuration.rb
@@ -134,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
136
  version: '0'
135
137
  requirements: []
136
138
  rubyforge_project:
137
- rubygems_version: 2.2.1
139
+ rubygems_version: 2.2.2
138
140
  signing_key:
139
141
  specification_version: 4
140
142
  summary: Ruby gem to handle settings for ActiveRecord instances by storing them as