configurable_engine 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +6 -14
  2. data/.document +5 -0
  3. data/.gitignore +43 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +18 -0
  6. data/Gemfile +2 -7
  7. data/Gemfile.lock +160 -54
  8. data/Rakefile +12 -39
  9. data/app/models/configurable.rb +36 -5
  10. data/app/views/admin/configurables/show.html.erb +1 -1
  11. data/config/cucumber.yml +8 -0
  12. data/configurable_engine.gemspec +22 -65
  13. data/features/admin_configurables.feature +10 -0
  14. data/features/step_definitions/web_steps.rb +219 -0
  15. data/features/support/env.rb +57 -0
  16. data/features/support/paths.rb +35 -0
  17. data/gemfiles/Gemfile.base +24 -0
  18. data/gemfiles/Gemfile.rails3_1 +2 -0
  19. data/gemfiles/Gemfile.rails3_1.lock +180 -0
  20. data/gemfiles/Gemfile.rails4_0 +2 -0
  21. data/gemfiles/Gemfile.rails4_0.lock +175 -0
  22. data/lib/configurable_engine/configurables_controller.rb +5 -4
  23. data/lib/configurable_engine/engine.rb +4 -0
  24. data/lib/configurable_engine/version.rb +3 -0
  25. data/spec/dummy/.gitignore +4 -0
  26. data/spec/dummy/README +256 -0
  27. data/spec/dummy/Rakefile +7 -0
  28. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  29. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  30. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  31. data/spec/dummy/config.ru +4 -0
  32. data/spec/dummy/config/application.rb +45 -0
  33. data/spec/dummy/config/boot.rb +13 -0
  34. data/spec/dummy/config/configurable.yml +27 -0
  35. data/spec/dummy/config/database.yml +29 -0
  36. data/spec/dummy/config/environment.rb +5 -0
  37. data/spec/dummy/config/environments/development.rb +24 -0
  38. data/spec/dummy/config/environments/production.rb +51 -0
  39. data/spec/dummy/config/environments/test.rb +85 -0
  40. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  41. data/spec/dummy/config/initializers/inflections.rb +10 -0
  42. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  43. data/spec/dummy/config/initializers/secret_token.rb +8 -0
  44. data/spec/dummy/config/initializers/session_store.rb +8 -0
  45. data/spec/dummy/config/locales/en.yml +5 -0
  46. data/spec/dummy/config/routes.rb +58 -0
  47. data/spec/dummy/db/migrate/20110110001344_create_configurables.rb +17 -0
  48. data/spec/dummy/db/schema.rb +25 -0
  49. data/spec/dummy/db/seeds.rb +7 -0
  50. data/spec/dummy/lib/tasks/.gitkeep +0 -0
  51. data/spec/dummy/public/404.html +26 -0
  52. data/spec/dummy/public/422.html +26 -0
  53. data/spec/dummy/public/500.html +26 -0
  54. data/spec/dummy/public/favicon.ico +0 -0
  55. data/spec/dummy/public/images/rails.png +0 -0
  56. data/spec/dummy/public/index.html +239 -0
  57. data/spec/dummy/public/javascripts/application.js +2 -0
  58. data/spec/dummy/public/javascripts/controls.js +965 -0
  59. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  60. data/spec/dummy/public/javascripts/effects.js +1123 -0
  61. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  62. data/spec/dummy/public/javascripts/rails.js +175 -0
  63. data/spec/dummy/public/robots.txt +5 -0
  64. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  65. data/spec/dummy/script/rails +6 -0
  66. data/spec/dummy/vendor/plugins/.gitkeep +0 -0
  67. data/spec/models/configurable_spec.rb +134 -0
  68. data/spec/spec_helper.rb +27 -0
  69. data/tasks/cucumber.rake +56 -0
  70. metadata +120 -83
  71. data/VERSION +0 -1
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OGZiYTdlNTY5MDQyNjNiYmMxMDEzOGUwNGYwM2FmMGI5OGQ1ZTQ0Zg==
5
- data.tar.gz: !binary |-
6
- MDVlZTJjMjg3ZGM5OWJkZDA2NjcxMDVmODI3MGJmNWRjZmVjOGQ4MQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZGE5NWNkYWE4MzQ1YjkzYWNiZmQwODFiMzJkZGZjMjQ2ODQ3NTU4MjA0YWE2
10
- Y2I1MDM1N2UzMTM4MGY0NzcwMGQ2YTdiYjk3N2MxZTRlZDRjZDI4ZmQ1MDBj
11
- Zjc2ZThlMjYwOThhMTliM2YwZDkyMzc5MjAyNzdkYjhjN2EwMjA=
12
- data.tar.gz: !binary |-
13
- N2Y0MWEyNTMxODI4MDBiNjgyNTM2NWQ3Y2I3Y2ViNWNlZTVmODRjNzI0ZjZl
14
- YjMxYzcxNTQzODBmMWVmMDQ3ZmU2ODUxYjFiZDJkMWU1ZWU2N2VkZjFiOTg1
15
- ZTNiMjcxMjk4NmYwYWZlZWMxNDAxZGQ5YzZmMDEyMzlmNzQ0NTc=
2
+ SHA1:
3
+ metadata.gz: cb3a943a784294cf89013a42e8f31eaa51ca79be
4
+ data.tar.gz: 5269001890ee44f5f7af4c01be487fd11ee19242
5
+ SHA512:
6
+ metadata.gz: ea7eadc32bab5381d3ff5d37d4046d7651ca42efa2f8cdfd25b7bb94bd52ba2791b2cad44f76e8d7f78d9576adf8894658a4226f6f09bce8949ee2c27072604c
7
+ data.tar.gz: 1cdaad24d66960ac916dad4398d9c21055fdb4c5775c67aad36e5388ada409aa56eec7b67c697ac6a7753380d5b2c5d80b4cfed4d840662bdb6118d5ae54c68a
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,43 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ #
19
+ # * Create a file at ~/.gitignore
20
+ # * Include files you want ignored
21
+ # * Run: git config --global core.excludesfile ~/.gitignore
22
+ #
23
+ # After doing this, these files will be ignored in all your git projects,
24
+ # saving you from having to 'pollute' every project you touch with them
25
+ #
26
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
+ #
28
+ # For MacOS:
29
+ #
30
+ #.DS_Store
31
+ #
32
+ # For TextMate
33
+ #*.tmproj
34
+ #tmtags
35
+ #
36
+ # For emacs:
37
+ #*~
38
+ #\#*
39
+ #.\#*
40
+ #
41
+ # For vim:
42
+ #*.swp
43
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ env:
7
+ - DB=sqlite
8
+ - DB=mysql
9
+ - DB=postgresql
10
+ gemfile:
11
+ - Gemfile
12
+ - gemfiles/Gemfile.rails3_1
13
+ - gemfiles/Gemfile.rails4_0
14
+ before_script:
15
+ - mysql -e 'create database strano_test'
16
+ - psql -c 'create database strano_test' -U postgres
17
+ - RAILS_ENV=test rake app:db:migrate
18
+ - rake app:db:test:prepare
data/Gemfile CHANGED
@@ -1,8 +1,3 @@
1
- source 'http://rubygems.org'
1
+ instance_eval File.read(File.expand_path('../gemfiles/Gemfile.base', __FILE__))
2
2
 
3
- group :development do
4
- gem 'jeweler'
5
- gem 'rake'
6
- gem 'rspec'
7
- gem 'cucumber'
8
- end
3
+ gem 'rails', '~>3.2.0'
data/Gemfile.lock CHANGED
@@ -1,72 +1,178 @@
1
1
  GEM
2
- remote: http://rubygems.org/
2
+ remote: https://rubygems.org/
3
3
  specs:
4
- addressable (2.3.5)
5
- builder (3.2.2)
6
- cucumber (1.3.8)
4
+ actionmailer (3.2.17)
5
+ actionpack (= 3.2.17)
6
+ mail (~> 2.5.4)
7
+ actionpack (3.2.17)
8
+ activemodel (= 3.2.17)
9
+ activesupport (= 3.2.17)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.4)
13
+ rack (~> 1.4.5)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.2.1)
17
+ activemodel (3.2.17)
18
+ activesupport (= 3.2.17)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.17)
21
+ activemodel (= 3.2.17)
22
+ activesupport (= 3.2.17)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activerecord-jdbc-adapter (1.3.6)
26
+ activerecord (>= 2.2)
27
+ activerecord-jdbcmysql-adapter (1.3.6)
28
+ activerecord-jdbc-adapter (~> 1.3.6)
29
+ jdbc-mysql (>= 5.1.22)
30
+ activerecord-jdbcpostgresql-adapter (1.3.6)
31
+ activerecord-jdbc-adapter (~> 1.3.6)
32
+ jdbc-postgres (>= 9.1)
33
+ activerecord-jdbcsqlite3-adapter (1.3.6)
34
+ activerecord-jdbc-adapter (~> 1.3.6)
35
+ jdbc-sqlite3 (~> 3.7.2)
36
+ activeresource (3.2.17)
37
+ activemodel (= 3.2.17)
38
+ activesupport (= 3.2.17)
39
+ activesupport (3.2.17)
40
+ i18n (~> 0.6, >= 0.6.4)
41
+ multi_json (~> 1.0)
42
+ arel (3.0.3)
43
+ bouncy-castle-java (1.5.0147)
44
+ builder (3.0.4)
45
+ capybara (2.2.1)
46
+ mime-types (>= 1.16)
47
+ nokogiri (>= 1.3.3)
48
+ rack (>= 1.0.0)
49
+ rack-test (>= 0.5.4)
50
+ xpath (~> 2.0)
51
+ coderay (1.1.0)
52
+ cucumber (1.3.11)
7
53
  builder (>= 2.1.2)
8
54
  diff-lcs (>= 1.1.3)
9
- gherkin (~> 2.12.1)
55
+ gherkin (~> 2.12)
10
56
  multi_json (>= 1.7.5, < 2.0)
11
57
  multi_test (>= 0.0.2)
12
- diff-lcs (1.2.4)
13
- faraday (0.8.8)
14
- multipart-post (~> 1.2.0)
15
- gherkin (2.12.1)
58
+ cucumber-rails (1.4.0)
59
+ capybara (>= 1.1.2)
60
+ cucumber (>= 1.2.0)
61
+ nokogiri (>= 1.5.0)
62
+ rails (>= 3.0.0)
63
+ database_cleaner (1.2.0)
64
+ diff-lcs (1.2.5)
65
+ erubis (2.7.0)
66
+ ffi (1.9.3-java)
67
+ gherkin (2.12.2)
68
+ multi_json (~> 1.3)
69
+ gherkin (2.12.2-java)
16
70
  multi_json (~> 1.3)
17
- git (1.2.6)
18
- github_api (0.10.1)
19
- addressable
20
- faraday (~> 0.8.1)
21
- hashie (>= 1.2)
22
- multi_json (~> 1.4)
23
- nokogiri (~> 1.5.2)
24
- oauth2
25
- hashie (2.0.5)
26
- highline (1.6.19)
27
- httpauth (0.2.0)
28
- jeweler (1.8.7)
29
- builder
71
+ hike (1.2.3)
72
+ i18n (0.6.9)
73
+ jdbc-mysql (5.1.28)
74
+ jdbc-postgres (9.3.1100)
75
+ jdbc-sqlite3 (3.7.2.1)
76
+ journey (1.0.4)
77
+ jruby-openssl (0.9.4)
78
+ bouncy-castle-java (>= 1.5.0147)
79
+ json (1.8.1)
80
+ json (1.8.1-java)
81
+ mail (2.5.4)
82
+ mime-types (~> 1.16)
83
+ treetop (~> 1.4.8)
84
+ method_source (0.8.2)
85
+ mime-types (1.25.1)
86
+ mini_portile (0.5.2)
87
+ multi_json (1.8.4)
88
+ multi_test (0.0.3)
89
+ mysql2 (0.3.15)
90
+ nokogiri (1.6.1)
91
+ mini_portile (~> 0.5.0)
92
+ nokogiri (1.6.1-java)
93
+ mini_portile (~> 0.5.0)
94
+ pg (0.17.1)
95
+ polyglot (0.3.4)
96
+ pry (0.9.12.6)
97
+ coderay (~> 1.0)
98
+ method_source (~> 0.8)
99
+ slop (~> 3.4)
100
+ pry (0.9.12.6-java)
101
+ coderay (~> 1.0)
102
+ method_source (~> 0.8)
103
+ slop (~> 3.4)
104
+ spoon (~> 0.0)
105
+ rack (1.4.5)
106
+ rack-cache (1.2)
107
+ rack (>= 0.4)
108
+ rack-ssl (1.3.3)
109
+ rack
110
+ rack-test (0.6.2)
111
+ rack (>= 1.0)
112
+ rails (3.2.17)
113
+ actionmailer (= 3.2.17)
114
+ actionpack (= 3.2.17)
115
+ activerecord (= 3.2.17)
116
+ activeresource (= 3.2.17)
117
+ activesupport (= 3.2.17)
30
118
  bundler (~> 1.0)
31
- git (>= 1.2.5)
32
- github_api (= 0.10.1)
33
- highline (>= 1.6.15)
34
- nokogiri (= 1.5.10)
35
- rake
36
- rdoc
37
- json (1.8.0)
38
- jwt (0.1.8)
39
- multi_json (>= 1.5)
40
- multi_json (1.8.0)
41
- multi_test (0.0.2)
42
- multi_xml (0.5.5)
43
- multipart-post (1.2.0)
44
- nokogiri (1.5.10)
45
- oauth2 (0.9.2)
46
- faraday (~> 0.8)
47
- httpauth (~> 0.2)
48
- jwt (~> 0.1.4)
49
- multi_json (~> 1.0)
50
- multi_xml (~> 0.5)
51
- rack (~> 1.2)
52
- rack (1.5.2)
53
- rake (10.1.0)
54
- rdoc (4.0.1)
119
+ railties (= 3.2.17)
120
+ railties (3.2.17)
121
+ actionpack (= 3.2.17)
122
+ activesupport (= 3.2.17)
123
+ rack-ssl (~> 1.3.2)
124
+ rake (>= 0.8.7)
125
+ rdoc (~> 3.4)
126
+ thor (>= 0.14.6, < 2.0)
127
+ rake (10.1.1)
128
+ rdoc (3.12.2)
55
129
  json (~> 1.4)
56
- rspec (2.14.1)
130
+ rspec-core (2.14.8)
131
+ rspec-expectations (2.14.5)
132
+ diff-lcs (>= 1.1.3, < 2.0)
133
+ rspec-mocks (2.14.6)
134
+ rspec-rails (2.14.1)
135
+ actionpack (>= 3.0)
136
+ activemodel (>= 3.0)
137
+ activesupport (>= 3.0)
138
+ railties (>= 3.0)
57
139
  rspec-core (~> 2.14.0)
58
140
  rspec-expectations (~> 2.14.0)
59
141
  rspec-mocks (~> 2.14.0)
60
- rspec-core (2.14.5)
61
- rspec-expectations (2.14.3)
62
- diff-lcs (>= 1.1.3, < 2.0)
63
- rspec-mocks (2.14.3)
142
+ slop (3.4.7)
143
+ spoon (0.0.4)
144
+ ffi
145
+ sprockets (2.2.2)
146
+ hike (~> 1.2)
147
+ multi_json (~> 1.0)
148
+ rack (~> 1.0)
149
+ tilt (~> 1.1, != 1.3.0)
150
+ sqlite3 (1.3.9)
151
+ thor (0.18.1)
152
+ tilt (1.4.1)
153
+ treetop (1.4.15)
154
+ polyglot
155
+ polyglot (>= 0.3.1)
156
+ tzinfo (0.3.38)
157
+ xpath (2.0.0)
158
+ nokogiri (~> 1.3)
64
159
 
65
160
  PLATFORMS
161
+ java
66
162
  ruby
67
163
 
68
164
  DEPENDENCIES
69
- cucumber
70
- jeweler
165
+ activerecord-jdbcmysql-adapter
166
+ activerecord-jdbcpostgresql-adapter
167
+ activerecord-jdbcsqlite3-adapter
168
+ capybara
169
+ cucumber-rails
170
+ database_cleaner
171
+ jruby-openssl
172
+ mysql2
173
+ pg
174
+ pry
175
+ rails (~> 3.2.0)
71
176
  rake
72
- rspec
177
+ rspec-rails
178
+ sqlite3
data/Rakefile CHANGED
@@ -1,45 +1,18 @@
1
- require 'rubygems'
2
- require 'bundler'
1
+ #!/usr/bin/env rake
3
2
  begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
9
6
  end
10
- require 'rake'
11
7
 
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "configurable_engine"
16
- gem.homepage = "http://github.com/paulca/configurable_engine"
17
- gem.license = "MIT"
18
- gem.summary = %Q{Database-backed configuration for Rails 3, with defaults from config file.}
19
- gem.description = %Q{Configurable is a Rails 3 engine that allows you to set up config variables in a config file, specifying default values for all environments. These variables can then be set on a per-app basis using a user facing configuration screen. }
20
- gem.email = "paul@rslw.com"
21
- gem.authors = ["Paul Campbell"]
22
- # Include your dependencies below. Runtime dependencies are required when using your gem,
23
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
- gem.add_runtime_dependency 'rails', '>3'
25
- gem.add_runtime_dependency 'activerecord', '>3'
26
- gem.files = FileList["[A-Za-z]*", "lib/**/*", "app/**/*", "config/*"]
27
- end
28
- # Jeweler::RubygemsDotOrgTasks.new
8
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
9
+ load 'rails/tasks/engine.rake'
29
10
 
30
- require 'rspec/core'
11
+ Bundler::GemHelper.install_tasks
12
+ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
13
+ # require 'rspec/core'
31
14
  require 'rspec/core/rake_task'
32
- RSpec::Core::RakeTask.new(:spec) do |spec|
33
- spec.pattern = FileList['spec/**/*_spec.rb']
34
- end
35
-
36
- RSpec::Core::RakeTask.new(:rcov) do |spec|
37
- spec.pattern = 'spec/**/*_spec.rb'
38
- spec.rcov = true
39
- end
40
-
41
- require 'cucumber/rake/task'
42
- Cucumber::Rake::Task.new(:features)
43
-
44
- task :default => :spec
45
15
 
16
+ desc "Run all specs in spec directory (excluding plugin specs)"
17
+ RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
18
+ task :default => [:spec, :cucumber]
@@ -1,10 +1,14 @@
1
1
  class Configurable < ActiveRecord::Base
2
2
 
3
- validates_presence_of :name
4
- validates_uniqueness_of :name
3
+ after_save :invalidate_cache, if: -> { ConfigurableEngine::Engine.config.use_cache }
4
+
5
+ validates_presence_of :name
6
+ validates_uniqueness_of :name
7
+
8
+ validate :type_of_value
5
9
 
6
10
  def self.defaults
7
- HashWithIndifferentAccess.new(
11
+ @defaults ||= HashWithIndifferentAccess.new(
8
12
  YAML.load_file(
9
13
  Rails.root.join('config', 'configurable.yml')
10
14
  )
@@ -27,7 +31,15 @@ class Configurable < ActiveRecord::Base
27
31
  def self.[](key)
28
32
  return self.defaults[key][:default] unless table_exists?
29
33
 
30
- value = find_by_name(key).try(:value) || self.defaults[key][:default]
34
+ value = if ConfigurableEngine::Engine.config.use_cache
35
+ Rails.cache.fetch("configurable_engine:#{key}") {
36
+ find_by_name(key).try(:value)
37
+ }
38
+ else
39
+ find_by_name(key).try(:value)
40
+ end
41
+
42
+ value ||= self.defaults[key][:default]
31
43
  case self.defaults[key][:type]
32
44
  when 'boolean'
33
45
  [true, 1, "1", "t", "true"].include?(value)
@@ -56,4 +68,23 @@ class Configurable < ActiveRecord::Base
56
68
  end
57
69
  end
58
70
 
59
- end
71
+ private
72
+
73
+ def type_of_value
74
+ return unless name
75
+ case Configurable.defaults[name][:type]
76
+ when 'boolean'
77
+ [true, 1, "1", "true", false, 0, "0", "false"].include?(value)
78
+ when 'decimal'
79
+ Float(value) rescue errors.add(:value, I18n.t("activerecord.errors.messages.invalid"))
80
+ when 'integer'
81
+ Integer(value) rescue errors.add(:value, I18n.t("activerecord.errors.messages.invalid"))
82
+ when 'list'
83
+ value.is_a?(Array) rescue errors.add(:value, I18n.t("activerecord.errors.messages.invalid"))
84
+ end
85
+ end
86
+
87
+ def invalidate_cache
88
+ Rails.cache.delete("configurable_engine:#{self.name}")
89
+ end
90
+ end