ledermann-rails-settings 1.2.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +14 -6
  4. data/Gemfile +1 -1
  5. data/MIT-LICENSE +6 -5
  6. data/README.md +171 -158
  7. data/Rakefile +4 -9
  8. data/ci/Gemfile-rails-4-2 +7 -0
  9. data/ci/Gemfile-rails-5-0 +6 -0
  10. data/ci/Gemfile-rails-5-1 +6 -0
  11. data/ci/Gemfile-rails-5-2 +6 -0
  12. data/ci/Gemfile-rails-6-0 +6 -0
  13. data/lib/generators/rails_settings/migration/migration_generator.rb +23 -0
  14. data/lib/generators/rails_settings/migration/templates/migration.rb +21 -0
  15. data/lib/ledermann-rails-settings.rb +1 -0
  16. data/lib/rails-settings.rb +21 -5
  17. data/lib/rails-settings/base.rb +48 -0
  18. data/lib/rails-settings/configuration.rb +39 -0
  19. data/lib/rails-settings/scopes.rb +34 -0
  20. data/lib/rails-settings/setting_object.rb +84 -0
  21. data/lib/rails-settings/version.rb +2 -2
  22. data/rails-settings.gemspec +22 -21
  23. data/spec/configuration_spec.rb +120 -0
  24. data/spec/database.yml +3 -0
  25. data/spec/queries_spec.rb +101 -0
  26. data/spec/scopes_spec.rb +31 -0
  27. data/spec/serialize_spec.rb +40 -0
  28. data/spec/setting_object_spec.rb +153 -0
  29. data/spec/settings_spec.rb +248 -0
  30. data/spec/spec_helper.rb +111 -0
  31. data/spec/support/matchers/perform_queries.rb +22 -0
  32. data/spec/support/query_counter.rb +17 -0
  33. metadata +130 -118
  34. data/Changelog.md +0 -17
  35. data/ci/Gemfile.rails-2.3.x +0 -5
  36. data/ci/Gemfile.rails-3.0.x +0 -5
  37. data/ci/Gemfile.rails-3.1.x +0 -5
  38. data/ci/Gemfile.rails-3.2.x +0 -5
  39. data/init.rb +0 -1
  40. data/lib/rails-settings/active_record.rb +0 -38
  41. data/lib/rails-settings/null_store.rb +0 -48
  42. data/lib/rails-settings/scoped_settings.rb +0 -14
  43. data/lib/rails-settings/settings.rb +0 -142
  44. data/test/settings_test.rb +0 -252
  45. data/test/test_helper.rb +0 -34
@@ -0,0 +1,111 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ])
8
+ SimpleCov.start do
9
+ add_filter '/spec/'
10
+ end
11
+
12
+ # Requires supporting ruby files with custom matchers and macros, etc,
13
+ # in spec/support/ and its subdirectories.
14
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
15
+
16
+ # This file was generated by the `rspec --init` command. Conventionally, all
17
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
18
+ # Require this file using `require "spec_helper"` to ensure that it is only
19
+ # loaded once.
20
+ #
21
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
22
+ RSpec.configure do |config|
23
+ # Run specs in random order to surface order dependencies. If you find an
24
+ # order dependency and want to debug it, you can fix the order by providing
25
+ # the seed, which is printed after each run.
26
+ # --seed 1234
27
+ # config.order = 'random'
28
+
29
+ config.before(:each) do
30
+ clear_db
31
+ end
32
+
33
+ config.after :suite do
34
+ RailsSettingsMigration.migrate(:down)
35
+ end
36
+ end
37
+
38
+ require 'active_record'
39
+ require 'protected_attributes' if ENV['PROTECTED_ATTRIBUTES'] == 'true'
40
+ require 'rails-settings'
41
+
42
+ if I18n.respond_to?(:enforce_available_locales=)
43
+ I18n.enforce_available_locales = false
44
+ end
45
+
46
+ class User < ActiveRecord::Base
47
+ has_settings do |s|
48
+ s.key :dashboard, :defaults => { :theme => 'blue', :view => 'monthly', :filter => true }
49
+ s.key :calendar, :defaults => { :scope => 'company'}
50
+ end
51
+ end
52
+
53
+ class GuestUser < User
54
+ has_settings do |s|
55
+ s.key :dashboard, :defaults => { :theme => 'red', :view => 'monthly', :filter => true }
56
+ end
57
+ end
58
+
59
+ class Account < ActiveRecord::Base
60
+ has_settings :portal
61
+ end
62
+
63
+ class Project < ActiveRecord::Base
64
+ has_settings :info, :class_name => 'ProjectSettingObject'
65
+ end
66
+
67
+ class ProjectSettingObject < RailsSettings::SettingObject
68
+ validate do
69
+ unless self.owner_name.present? && self.owner_name.is_a?(String)
70
+ errors.add(:base, "Owner name is missing")
71
+ end
72
+ end
73
+ end
74
+
75
+ def setup_db
76
+ ActiveRecord::Base.configurations = YAML.load_file(File.dirname(__FILE__) + '/database.yml')
77
+ ActiveRecord::Base.establish_connection(:sqlite)
78
+ ActiveRecord::Migration.verbose = false
79
+
80
+ print "Testing with ActiveRecord #{ActiveRecord::VERSION::STRING}"
81
+ if ActiveRecord::VERSION::MAJOR == 4
82
+ print " #{defined?(ProtectedAttributes) ? 'with' : 'without'} gem `protected_attributes`"
83
+ end
84
+ puts
85
+
86
+ require File.expand_path('../../lib/generators/rails_settings/migration/templates/migration.rb', __FILE__)
87
+ RailsSettingsMigration.migrate(:up)
88
+
89
+ ActiveRecord::Schema.define(:version => 1) do
90
+ create_table :users do |t|
91
+ t.string :type
92
+ t.string :name
93
+ end
94
+
95
+ create_table :accounts do |t|
96
+ t.string :subdomain
97
+ end
98
+
99
+ create_table :projects do |t|
100
+ t.string :name
101
+ end
102
+ end
103
+ end
104
+
105
+ def clear_db
106
+ User.delete_all
107
+ Account.delete_all
108
+ RailsSettings::SettingObject.delete_all
109
+ end
110
+
111
+ setup_db
@@ -0,0 +1,22 @@
1
+ RSpec::Matchers.define :perform_queries do |expected|
2
+ match do |block|
3
+ query_count(&block) == expected
4
+ end
5
+
6
+ failure_message do |actual|
7
+ "Expected to run #{expected} queries, got #{@counter.query_count}"
8
+ end
9
+
10
+ def query_count(&block)
11
+ @counter = ActiveRecord::QueryCounter.new
12
+ ActiveSupport::Notifications.subscribe('sql.active_record', @counter.to_proc)
13
+ yield
14
+ ActiveSupport::Notifications.unsubscribe(@counter.to_proc)
15
+
16
+ @counter.query_count
17
+ end
18
+
19
+ def supports_block_expectations?
20
+ true
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ module ActiveRecord
2
+ class QueryCounter
3
+ attr_reader :query_count
4
+
5
+ def initialize
6
+ @query_count = 0
7
+ end
8
+
9
+ def to_proc
10
+ lambda(&method(:callback))
11
+ end
12
+
13
+ def callback(name, start, finish, message_id, values)
14
+ @query_count += 1 unless %w(CACHE SCHEMA).include?(values[:name]) || values[:sql] =~ /^begin/i || values[:sql] =~ /^commit/i
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -1,157 +1,169 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ledermann-rails-settings
3
- version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease:
6
- segments:
7
- - 1
8
- - 2
9
- - 0
10
- version: 1.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.5.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Georg Ledermann
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-07-21 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: rake
11
+ date: 2019-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
22
21
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
26
31
  - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
32
34
  type: :development
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: sqlite3
36
35
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
- requirements:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
40
38
  - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
46
48
  type: :development
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: activerecord
50
49
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
54
52
  - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 5
57
- segments:
58
- - 2
59
- - 3
60
- version: "2.3"
61
- type: :runtime
62
- version_requirements: *id003
63
- - !ruby/object:Gem::Dependency
64
- name: rake
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
65
63
  prerelease: false
66
- requirement: &id004 !ruby/object:Gem::Requirement
67
- none: false
68
- requirements:
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
69
73
  - - ">="
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
- version: "0"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
75
76
  type: :development
76
- version_requirements: *id004
77
- - !ruby/object:Gem::Dependency
78
- name: sqlite3
79
77
  prerelease: false
80
- requirement: &id005 !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
83
87
  - - ">="
84
- - !ruby/object:Gem::Version
85
- hash: 3
86
- segments:
87
- - 0
88
- version: "0"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.11.2
89
90
  type: :development
90
- version_requirements: *id005
91
- description: Ruby Gem that makes managing a table of key/value pairs easy. Think of it like a Hash stored in you database, that uses simple ActiveRecord like methods for manipulation.
92
- email:
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 0.11.2
97
+ description: Settings gem for Ruby on Rails
98
+ email:
93
99
  - mail@georg-ledermann.de
94
100
  executables: []
95
-
96
101
  extensions: []
97
-
98
102
  extra_rdoc_files: []
99
-
100
- files:
101
- - .gitignore
102
- - .travis.yml
103
- - Changelog.md
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
104
106
  - Gemfile
105
107
  - MIT-LICENSE
106
108
  - README.md
107
109
  - Rakefile
108
- - ci/Gemfile.rails-2.3.x
109
- - ci/Gemfile.rails-3.0.x
110
- - ci/Gemfile.rails-3.1.x
111
- - ci/Gemfile.rails-3.2.x
112
- - init.rb
110
+ - ci/Gemfile-rails-4-2
111
+ - ci/Gemfile-rails-5-0
112
+ - ci/Gemfile-rails-5-1
113
+ - ci/Gemfile-rails-5-2
114
+ - ci/Gemfile-rails-6-0
115
+ - lib/generators/rails_settings/migration/migration_generator.rb
116
+ - lib/generators/rails_settings/migration/templates/migration.rb
117
+ - lib/ledermann-rails-settings.rb
113
118
  - lib/rails-settings.rb
114
- - lib/rails-settings/active_record.rb
115
- - lib/rails-settings/null_store.rb
116
- - lib/rails-settings/scoped_settings.rb
117
- - lib/rails-settings/settings.rb
119
+ - lib/rails-settings/base.rb
120
+ - lib/rails-settings/configuration.rb
121
+ - lib/rails-settings/scopes.rb
122
+ - lib/rails-settings/setting_object.rb
118
123
  - lib/rails-settings/version.rb
119
124
  - rails-settings.gemspec
120
- - test/settings_test.rb
121
- - test/test_helper.rb
125
+ - spec/configuration_spec.rb
126
+ - spec/database.yml
127
+ - spec/queries_spec.rb
128
+ - spec/scopes_spec.rb
129
+ - spec/serialize_spec.rb
130
+ - spec/setting_object_spec.rb
131
+ - spec/settings_spec.rb
132
+ - spec/spec_helper.rb
133
+ - spec/support/matchers/perform_queries.rb
134
+ - spec/support/query_counter.rb
122
135
  homepage: https://github.com/ledermann/rails-settings
123
- licenses: []
124
-
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
125
139
  post_install_message:
126
140
  rdoc_options: []
127
-
128
- require_paths:
141
+ require_paths:
129
142
  - lib
130
- required_ruby_version: !ruby/object:Gem::Requirement
131
- none: false
132
- requirements:
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
133
145
  - - ">="
134
- - !ruby/object:Gem::Version
135
- hash: 3
136
- segments:
137
- - 0
138
- version: "0"
139
- required_rubygems_version: !ruby/object:Gem::Requirement
140
- none: false
141
- requirements:
146
+ - !ruby/object:Gem::Version
147
+ version: '2.4'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
142
150
  - - ">="
143
- - !ruby/object:Gem::Version
144
- hash: 3
145
- segments:
146
- - 0
147
- version: "0"
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
148
153
  requirements: []
149
-
150
- rubyforge_project: ledermann-rails-settings
151
- rubygems_version: 1.8.24
154
+ rubygems_version: 3.0.6
152
155
  signing_key:
153
- specification_version: 3
154
- summary: Settings management for ActiveRecord objects
155
- test_files:
156
- - test/settings_test.rb
157
- - test/test_helper.rb
156
+ specification_version: 4
157
+ summary: Ruby gem to handle settings for ActiveRecord instances by storing them as
158
+ serialized Hash in a separate database table. Namespaces and defaults included.
159
+ test_files:
160
+ - spec/configuration_spec.rb
161
+ - spec/database.yml
162
+ - spec/queries_spec.rb
163
+ - spec/scopes_spec.rb
164
+ - spec/serialize_spec.rb
165
+ - spec/setting_object_spec.rb
166
+ - spec/settings_spec.rb
167
+ - spec/spec_helper.rb
168
+ - spec/support/matchers/perform_queries.rb
169
+ - spec/support/query_counter.rb
data/Changelog.md DELETED
@@ -1,17 +0,0 @@
1
- Version 1.2.0 (2012-07-21)
2
-
3
- - Added model-level settings (thanks to Jim Ryan)
4
-
5
- Version 1.1.0 (2012-06-01)
6
-
7
- - Added caching (thanks to Matthew McEachen)
8
-
9
- Version 1.0.1 (2011-11-05)
10
-
11
- - Gemspec: Fixed missing dependency
12
-
13
- Version 1.0.0 (2011-11-05)
14
-
15
- - Conversion from Plugin to Gem
16
- - Destroying false values (thanks to @Pavling)
17
- - Testing with Travis