configvars_rails 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.project +1 -0
- data/.travis.yml +12 -0
- data/Gemfile +7 -5
- data/Gemfile.lock +91 -58
- data/Gemfile.rails3 +11 -0
- data/Gemfile.rails4 +11 -0
- data/VERSION +1 -1
- data/configvars_rails.gemspec +26 -16
- data/lib/configvars_rails/controller.rb +29 -16
- data/lib/configvars_rails/generators/templates/001_create_config_vars.rb +3 -3
- data/lib/configvars_rails/generators/templates/config_vars/edit.html.erb +2 -2
- data/lib/configvars_rails/generators/templates/config_vars/index.html.erb +2 -2
- data/lib/configvars_rails/model.rb +5 -5
- data/lib/configvars_rails/routes.rb +7 -8
- data/test/config_var_test.rb +2 -2
- data/test/config_vars_controller_api_test.rb +10 -11
- data/test/helpers/db_setup.rb +16 -4
- data/test/helpers/rails.rb +8 -2
- data/test/helpers/routes.rb +8 -2
- data/test/routes_test.rb +13 -14
- metadata +74 -35
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 25e308bc1f988ecdb0f724e46c93b72a11e9a532
|
4
|
+
data.tar.gz: 8552099b84de63bc7835d6336401baafa68c03ef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b48af680f2fde547c4db473f16d16e0943f9b31fec1142738b3731d5ce8a466fae969fe6d4c4244fd73c64d53f9e8dc9c5aa68b30f42ea54b24e5bba1b1e5be7
|
7
|
+
data.tar.gz: a63fd4be66995cd3b4822adc5747419a88bdbeee13b6f10e02abac8cdd9442aa4b73dab4acbec90da7a408f6399d11e265a6fe14e5915d23cb3a4945d948858d
|
data/.project
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
source
|
2
|
-
gem
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
gem 'rails', '>= 3.2.16'
|
3
3
|
|
4
4
|
group :development do
|
5
|
-
gem
|
6
|
-
gem
|
7
|
-
gem
|
5
|
+
gem 'bundler', '>= 1.3.5'
|
6
|
+
gem 'jeweler', '>= 1.8.8'
|
7
|
+
gem 'mysql2', '>= 0.3.14'
|
8
|
+
gem 'pg', '>= 0.17.0'
|
9
|
+
gem 'sqlite3', '>= 1.3.8'
|
8
10
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,95 +1,128 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
actionmailer (3.2.
|
5
|
-
actionpack (= 3.2.
|
6
|
-
mail (~> 2.4
|
7
|
-
actionpack (3.2.
|
8
|
-
activemodel (= 3.2.
|
9
|
-
activesupport (= 3.2.
|
4
|
+
actionmailer (3.2.16)
|
5
|
+
actionpack (= 3.2.16)
|
6
|
+
mail (~> 2.5.4)
|
7
|
+
actionpack (3.2.16)
|
8
|
+
activemodel (= 3.2.16)
|
9
|
+
activesupport (= 3.2.16)
|
10
10
|
builder (~> 3.0.0)
|
11
11
|
erubis (~> 2.7.0)
|
12
|
-
journey (~> 1.0.
|
13
|
-
rack (~> 1.4.
|
14
|
-
rack-cache (~> 1.
|
12
|
+
journey (~> 1.0.4)
|
13
|
+
rack (~> 1.4.5)
|
14
|
+
rack-cache (~> 1.2)
|
15
15
|
rack-test (~> 0.6.1)
|
16
|
-
sprockets (~> 2.1
|
17
|
-
activemodel (3.2.
|
18
|
-
activesupport (= 3.2.
|
16
|
+
sprockets (~> 2.2.1)
|
17
|
+
activemodel (3.2.16)
|
18
|
+
activesupport (= 3.2.16)
|
19
19
|
builder (~> 3.0.0)
|
20
|
-
activerecord (3.2.
|
21
|
-
activemodel (= 3.2.
|
22
|
-
activesupport (= 3.2.
|
20
|
+
activerecord (3.2.16)
|
21
|
+
activemodel (= 3.2.16)
|
22
|
+
activesupport (= 3.2.16)
|
23
23
|
arel (~> 3.0.2)
|
24
24
|
tzinfo (~> 0.3.29)
|
25
|
-
activeresource (3.2.
|
26
|
-
activemodel (= 3.2.
|
27
|
-
activesupport (= 3.2.
|
28
|
-
activesupport (3.2.
|
29
|
-
i18n (~> 0.6)
|
25
|
+
activeresource (3.2.16)
|
26
|
+
activemodel (= 3.2.16)
|
27
|
+
activesupport (= 3.2.16)
|
28
|
+
activesupport (3.2.16)
|
29
|
+
i18n (~> 0.6, >= 0.6.4)
|
30
30
|
multi_json (~> 1.0)
|
31
|
-
|
32
|
-
|
31
|
+
addressable (2.3.5)
|
32
|
+
arel (3.0.3)
|
33
|
+
builder (3.0.4)
|
33
34
|
erubis (2.7.0)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
faraday (0.8.8)
|
36
|
+
multipart-post (~> 1.2.0)
|
37
|
+
git (1.2.6)
|
38
|
+
github_api (0.10.1)
|
39
|
+
addressable
|
40
|
+
faraday (~> 0.8.1)
|
41
|
+
hashie (>= 1.2)
|
42
|
+
multi_json (~> 1.4)
|
43
|
+
nokogiri (~> 1.5.2)
|
44
|
+
oauth2
|
45
|
+
hashie (2.0.5)
|
46
|
+
highline (1.6.20)
|
47
|
+
hike (1.2.3)
|
48
|
+
httpauth (0.2.0)
|
49
|
+
i18n (0.6.9)
|
50
|
+
jeweler (1.8.8)
|
51
|
+
builder
|
38
52
|
bundler (~> 1.0)
|
39
53
|
git (>= 1.2.5)
|
54
|
+
github_api (= 0.10.1)
|
55
|
+
highline (>= 1.6.15)
|
56
|
+
nokogiri (= 1.5.10)
|
40
57
|
rake
|
41
58
|
rdoc
|
42
|
-
journey (1.0.
|
43
|
-
json (1.
|
44
|
-
|
45
|
-
|
59
|
+
journey (1.0.4)
|
60
|
+
json (1.8.1)
|
61
|
+
jwt (0.1.8)
|
62
|
+
multi_json (>= 1.5)
|
63
|
+
mail (2.5.4)
|
46
64
|
mime-types (~> 1.16)
|
47
65
|
treetop (~> 1.4.8)
|
48
|
-
mime-types (1.
|
49
|
-
multi_json (1.
|
66
|
+
mime-types (1.25.1)
|
67
|
+
multi_json (1.8.2)
|
68
|
+
multi_xml (0.5.5)
|
69
|
+
multipart-post (1.2.0)
|
70
|
+
mysql2 (0.3.14)
|
71
|
+
nokogiri (1.5.10)
|
72
|
+
oauth2 (0.9.2)
|
73
|
+
faraday (~> 0.8)
|
74
|
+
httpauth (~> 0.2)
|
75
|
+
jwt (~> 0.1.4)
|
76
|
+
multi_json (~> 1.0)
|
77
|
+
multi_xml (~> 0.5)
|
78
|
+
rack (~> 1.2)
|
79
|
+
pg (0.17.0)
|
50
80
|
polyglot (0.3.3)
|
51
|
-
rack (1.4.
|
81
|
+
rack (1.4.5)
|
52
82
|
rack-cache (1.2)
|
53
83
|
rack (>= 0.4)
|
54
|
-
rack-ssl (1.3.
|
84
|
+
rack-ssl (1.3.3)
|
55
85
|
rack
|
56
|
-
rack-test (0.6.
|
86
|
+
rack-test (0.6.2)
|
57
87
|
rack (>= 1.0)
|
58
|
-
rails (3.2.
|
59
|
-
actionmailer (= 3.2.
|
60
|
-
actionpack (= 3.2.
|
61
|
-
activerecord (= 3.2.
|
62
|
-
activeresource (= 3.2.
|
63
|
-
activesupport (= 3.2.
|
88
|
+
rails (3.2.16)
|
89
|
+
actionmailer (= 3.2.16)
|
90
|
+
actionpack (= 3.2.16)
|
91
|
+
activerecord (= 3.2.16)
|
92
|
+
activeresource (= 3.2.16)
|
93
|
+
activesupport (= 3.2.16)
|
64
94
|
bundler (~> 1.0)
|
65
|
-
railties (= 3.2.
|
66
|
-
railties (3.2.
|
67
|
-
actionpack (= 3.2.
|
68
|
-
activesupport (= 3.2.
|
95
|
+
railties (= 3.2.16)
|
96
|
+
railties (3.2.16)
|
97
|
+
actionpack (= 3.2.16)
|
98
|
+
activesupport (= 3.2.16)
|
69
99
|
rack-ssl (~> 1.3.2)
|
70
100
|
rake (>= 0.8.7)
|
71
101
|
rdoc (~> 3.4)
|
72
|
-
thor (
|
73
|
-
rake (
|
74
|
-
rdoc (3.12)
|
102
|
+
thor (>= 0.14.6, < 2.0)
|
103
|
+
rake (10.1.0)
|
104
|
+
rdoc (3.12.2)
|
75
105
|
json (~> 1.4)
|
76
|
-
sprockets (2.
|
106
|
+
sprockets (2.2.2)
|
77
107
|
hike (~> 1.2)
|
108
|
+
multi_json (~> 1.0)
|
78
109
|
rack (~> 1.0)
|
79
110
|
tilt (~> 1.1, != 1.3.0)
|
80
|
-
sqlite3 (1.3.
|
81
|
-
thor (0.
|
82
|
-
tilt (1.
|
83
|
-
treetop (1.4.
|
111
|
+
sqlite3 (1.3.8)
|
112
|
+
thor (0.18.1)
|
113
|
+
tilt (1.4.1)
|
114
|
+
treetop (1.4.15)
|
84
115
|
polyglot
|
85
116
|
polyglot (>= 0.3.1)
|
86
|
-
tzinfo (0.3.
|
117
|
+
tzinfo (0.3.38)
|
87
118
|
|
88
119
|
PLATFORMS
|
89
120
|
ruby
|
90
121
|
|
91
122
|
DEPENDENCIES
|
92
|
-
bundler (>= 1.
|
93
|
-
jeweler (>= 1.8.
|
94
|
-
|
95
|
-
|
123
|
+
bundler (>= 1.3.5)
|
124
|
+
jeweler (>= 1.8.8)
|
125
|
+
mysql2 (>= 0.3.14)
|
126
|
+
pg (>= 0.17.0)
|
127
|
+
rails (>= 3.2.16)
|
128
|
+
sqlite3 (>= 1.3.8)
|
data/Gemfile.rails3
ADDED
data/Gemfile.rails4
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/configvars_rails.gemspec
CHANGED
@@ -2,14 +2,15 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: configvars_rails 0.6.0 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = "configvars_rails"
|
8
|
-
s.version = "0.
|
9
|
+
s.version = "0.6.0"
|
9
10
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
12
|
s.authors = ["Victor Costan"]
|
12
|
-
s.date = "
|
13
|
+
s.date = "2013-12-07"
|
13
14
|
s.description = "This gem provides a model and simple controller for\n storing global application configuration in a database. This allows the\n configuration to change without source code modifications."
|
14
15
|
s.email = "victor@costan.us"
|
15
16
|
s.extra_rdoc_files = [
|
@@ -18,8 +19,11 @@ Gem::Specification.new do |s|
|
|
18
19
|
]
|
19
20
|
s.files = [
|
20
21
|
".project",
|
22
|
+
".travis.yml",
|
21
23
|
"Gemfile",
|
22
24
|
"Gemfile.lock",
|
25
|
+
"Gemfile.rails3",
|
26
|
+
"Gemfile.rails4",
|
23
27
|
"LICENSE",
|
24
28
|
"README.rdoc",
|
25
29
|
"Rakefile",
|
@@ -62,28 +66,34 @@ Gem::Specification.new do |s|
|
|
62
66
|
s.homepage = "http://github.com/pwnall/configvars_rails"
|
63
67
|
s.licenses = ["MIT"]
|
64
68
|
s.require_paths = ["lib"]
|
65
|
-
s.rubygems_version = "1.
|
69
|
+
s.rubygems_version = "2.1.11"
|
66
70
|
s.summary = "Global configuration variables for Rails 3 applications."
|
67
71
|
|
68
72
|
if s.respond_to? :specification_version then
|
69
|
-
s.specification_version =
|
73
|
+
s.specification_version = 4
|
70
74
|
|
71
75
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
72
|
-
s.add_runtime_dependency(%q<rails>, [">= 3.2.
|
73
|
-
s.add_development_dependency(%q<bundler>, [">= 1.
|
74
|
-
s.add_development_dependency(%q<jeweler>, [">= 1.8.
|
75
|
-
s.add_development_dependency(%q<
|
76
|
+
s.add_runtime_dependency(%q<rails>, [">= 3.2.16"])
|
77
|
+
s.add_development_dependency(%q<bundler>, [">= 1.3.5"])
|
78
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.8.8"])
|
79
|
+
s.add_development_dependency(%q<mysql2>, [">= 0.3.14"])
|
80
|
+
s.add_development_dependency(%q<pg>, [">= 0.17.0"])
|
81
|
+
s.add_development_dependency(%q<sqlite3>, [">= 1.3.8"])
|
76
82
|
else
|
77
|
-
s.add_dependency(%q<rails>, [">= 3.2.
|
78
|
-
s.add_dependency(%q<bundler>, [">= 1.
|
79
|
-
s.add_dependency(%q<jeweler>, [">= 1.8.
|
80
|
-
s.add_dependency(%q<
|
83
|
+
s.add_dependency(%q<rails>, [">= 3.2.16"])
|
84
|
+
s.add_dependency(%q<bundler>, [">= 1.3.5"])
|
85
|
+
s.add_dependency(%q<jeweler>, [">= 1.8.8"])
|
86
|
+
s.add_dependency(%q<mysql2>, [">= 0.3.14"])
|
87
|
+
s.add_dependency(%q<pg>, [">= 0.17.0"])
|
88
|
+
s.add_dependency(%q<sqlite3>, [">= 1.3.8"])
|
81
89
|
end
|
82
90
|
else
|
83
|
-
s.add_dependency(%q<rails>, [">= 3.2.
|
84
|
-
s.add_dependency(%q<bundler>, [">= 1.
|
85
|
-
s.add_dependency(%q<jeweler>, [">= 1.8.
|
86
|
-
s.add_dependency(%q<
|
91
|
+
s.add_dependency(%q<rails>, [">= 3.2.16"])
|
92
|
+
s.add_dependency(%q<bundler>, [">= 1.3.5"])
|
93
|
+
s.add_dependency(%q<jeweler>, [">= 1.8.8"])
|
94
|
+
s.add_dependency(%q<mysql2>, [">= 0.3.14"])
|
95
|
+
s.add_dependency(%q<pg>, [">= 0.17.0"])
|
96
|
+
s.add_dependency(%q<sqlite3>, [">= 1.3.8"])
|
87
97
|
end
|
88
98
|
end
|
89
99
|
|
@@ -5,19 +5,19 @@ module ConfigvarsRails
|
|
5
5
|
|
6
6
|
# Included by the config vars management controller.
|
7
7
|
#
|
8
|
-
# Some parts of the codebase expect the controller to be named
|
8
|
+
# Some parts of the codebase expect the controller to be named
|
9
9
|
# ConfigVarsController.
|
10
10
|
module Controller
|
11
11
|
extend ActiveSupport::Concern
|
12
|
-
|
12
|
+
|
13
13
|
included do
|
14
14
|
layout 'config_vars'
|
15
15
|
end
|
16
16
|
|
17
17
|
# GET /config_vars
|
18
18
|
def index
|
19
|
-
@config_vars = ConfigVar.order(:name).
|
20
|
-
|
19
|
+
@config_vars = ConfigVar.order(:name).to_a
|
20
|
+
|
21
21
|
defined_names = ConfigvarsRails.variable_names
|
22
22
|
default_names = defined_names - @config_vars.map { |var| var.name.to_sym }
|
23
23
|
@default_vars = default_names.map { |name|
|
@@ -28,52 +28,51 @@ module Controller
|
|
28
28
|
format.html # index.html.erb
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
# GET /config_vars/http_user
|
33
33
|
def show
|
34
34
|
edit
|
35
|
-
render :
|
35
|
+
render text: @config_var.value
|
36
36
|
end
|
37
37
|
|
38
38
|
# GET /config_vars/http_user/edit
|
39
39
|
def edit
|
40
|
-
@config_var = ConfigVar.where(:
|
40
|
+
@config_var = ConfigVar.where(name: params[:name]).first
|
41
41
|
unless @config_var
|
42
|
-
@config_var = ConfigVar.new :
|
42
|
+
@config_var = ConfigVar.new name: params[:name]
|
43
43
|
if descriptor = ConfigvarsRails.variable_descriptor(params[:name])
|
44
44
|
@config_var.value = descriptor.default_value
|
45
45
|
end
|
46
|
-
end
|
46
|
+
end
|
47
47
|
end
|
48
48
|
|
49
49
|
# PUT /config_vars/http_user
|
50
50
|
def update
|
51
|
-
@config_var = ConfigVar.where(:
|
51
|
+
@config_var = ConfigVar.where(name: params[:config_var][:name]).first
|
52
52
|
unless @config_var
|
53
|
-
@config_var = ConfigVar.new
|
54
|
-
@config_var.name = params[:name]
|
53
|
+
@config_var = ConfigVar.new update_params[:config_var]
|
55
54
|
end
|
56
55
|
|
57
56
|
respond_to do |format|
|
58
57
|
success = if @config_var.new_record?
|
59
58
|
@config_var.save
|
60
59
|
else
|
61
|
-
@config_var.update_attributes
|
60
|
+
@config_var.update_attributes update_params[:config_var]
|
62
61
|
end
|
63
62
|
if success
|
64
63
|
format.html do
|
65
64
|
redirect_to config_vars_url,
|
66
|
-
:
|
65
|
+
notice: 'Configuration variable was successfully updated.'
|
67
66
|
end
|
68
67
|
else
|
69
|
-
format.html { render :
|
68
|
+
format.html { render action: :edit }
|
70
69
|
end
|
71
70
|
end
|
72
71
|
end
|
73
72
|
|
74
73
|
# DELETE /config_vars/http_user
|
75
74
|
def destroy
|
76
|
-
@config_var = ConfigVar.where(:
|
75
|
+
@config_var = ConfigVar.where(name: params[:name]).first
|
77
76
|
@config_var.destroy
|
78
77
|
|
79
78
|
respond_to do |format|
|
@@ -81,6 +80,20 @@ module Controller
|
|
81
80
|
end
|
82
81
|
end
|
83
82
|
|
83
|
+
if defined? ActiveModel::ForbiddenAttributesProtection
|
84
|
+
# Rails 4.
|
85
|
+
|
86
|
+
# Parameters used to change a config variable.
|
87
|
+
def update_params
|
88
|
+
params.permit config_var: [:name, :value]
|
89
|
+
end
|
90
|
+
else
|
91
|
+
# Rails 3.
|
92
|
+
def update_params
|
93
|
+
params
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
84
97
|
end # module ConfigvarsRails::Controller
|
85
98
|
|
86
99
|
end # namespace ConfigvarsRails
|
@@ -1,10 +1,10 @@
|
|
1
1
|
class CreateConfigVars < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table :config_vars do |t|
|
4
|
-
t.string :name, :
|
5
|
-
t.binary :value, :
|
4
|
+
t.string :name, length: 64, null: false
|
5
|
+
t.binary :value, length: 1024, null: false
|
6
6
|
end
|
7
|
-
add_index :config_vars, :name, :
|
7
|
+
add_index :config_vars, :name, unique: true
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.down
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<h2>Editing Configuration Variable</h2>
|
2
2
|
|
3
|
-
<%= form_for(@config_var, :
|
4
|
-
:
|
3
|
+
<%= form_for(@config_var, url: config_var_path,
|
4
|
+
html: { method: :put }) do |f| %>
|
5
5
|
<% if @config_var.errors.any? %>
|
6
6
|
<div id="error_explanation">
|
7
7
|
<h3><%= pluralize(@config_var.errors.count, "error") %> prohibited this config_var from being saved:</h3>
|
@@ -24,7 +24,7 @@
|
|
24
24
|
'undefined' %>
|
25
25
|
</td>
|
26
26
|
<td><%= link_to 'Edit', edit_config_var_path(config_var) %></td>
|
27
|
-
<td><%= link_to 'Reset to default', config_var, :
|
27
|
+
<td><%= link_to 'Reset to default', config_var, method: :delete %></td>
|
28
28
|
</tr>
|
29
29
|
<% end %>
|
30
30
|
</table>
|
@@ -46,7 +46,7 @@
|
|
46
46
|
<td><%= name %></td>
|
47
47
|
<td><%= descriptor.value_type %></td>
|
48
48
|
<td><%= descriptor.default_value %></td>
|
49
|
-
<td><%= link_to 'Edit', edit_config_var_path(:
|
49
|
+
<td><%= link_to 'Edit', edit_config_var_path(name: name) %></td>
|
50
50
|
</tr>
|
51
51
|
<% end %>
|
52
52
|
</table>
|
@@ -9,10 +9,10 @@ module Model
|
|
9
9
|
|
10
10
|
included do
|
11
11
|
# The name of the configuration variable.
|
12
|
-
validates :name, :
|
12
|
+
validates :name, uniqueness: true, length: 1..64, presence: true
|
13
13
|
|
14
14
|
# The value of the configuration variable.
|
15
|
-
validates :value, :
|
15
|
+
validates :value, length: 0..1024, exclusion: { in: [nil] }
|
16
16
|
end
|
17
17
|
|
18
18
|
|
@@ -20,7 +20,7 @@ module Model
|
|
20
20
|
module ClassMethods
|
21
21
|
# Access configuration flags by ConfigVar['flag_name'].
|
22
22
|
def [](name)
|
23
|
-
var = where(:
|
23
|
+
var = where(name: name).first
|
24
24
|
return var.value if var
|
25
25
|
|
26
26
|
descriptor = ConfigvarsRails.variable_descriptor name
|
@@ -31,8 +31,8 @@ module Model
|
|
31
31
|
|
32
32
|
# Set configuration flags by ConfigVar['flag_name'] = 'flag_value'.
|
33
33
|
def []=(name, value)
|
34
|
-
flag = where(:
|
35
|
-
flag ||= new :
|
34
|
+
flag = where(name: name).first
|
35
|
+
flag ||= new name: name
|
36
36
|
flag.value = value
|
37
37
|
flag.save!
|
38
38
|
value
|
@@ -9,15 +9,14 @@ module Routes
|
|
9
9
|
# :nodoc: mixed into ActionPack's route mapper.
|
10
10
|
module MapperMixin
|
11
11
|
def config_vars
|
12
|
-
get 'config_vars
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
get 'config_vars' => 'config_vars#index', as: :config_vars
|
13
|
+
get 'config_vars/:name/edit' => 'config_vars#edit', as: :edit_config_var,
|
14
|
+
constraints: { name: /[^\/]+/ }
|
15
|
+
get 'config_vars/:name' => 'config_vars#show', as: :config_var,
|
16
|
+
constraints: { name: /[^\/]+/ }
|
17
|
+
put 'config_vars' => 'config_vars#update'
|
18
18
|
delete 'config_vars/:name' => 'config_vars#destroy',
|
19
|
-
:
|
20
|
-
get 'config_vars' => 'config_vars#index', :as => :config_vars
|
19
|
+
constraints: { name: /[^\/]+/ }
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
data/test/config_var_test.rb
CHANGED
@@ -2,7 +2,7 @@ require File.expand_path('../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
class ConfigVarTest < ActiveSupport::TestCase
|
4
4
|
def setup
|
5
|
-
@var = ConfigVar.new :
|
5
|
+
@var = ConfigVar.new name: 'var', value: 'var_value'
|
6
6
|
end
|
7
7
|
|
8
8
|
test "setup" do
|
@@ -36,6 +36,6 @@ class ConfigVarTest < ActiveSupport::TestCase
|
|
36
36
|
test "convenience set" do
|
37
37
|
ConfigVar['other_var'] = 'other_value'
|
38
38
|
assert_equal 'other_value',
|
39
|
-
ConfigVar.where(:
|
39
|
+
ConfigVar.where(name: 'other_var').first.value
|
40
40
|
end
|
41
41
|
end
|
@@ -19,7 +19,7 @@ class ConfigVarsControllerApiTest < ActionController::TestCase
|
|
19
19
|
test "should get index" do
|
20
20
|
get :index
|
21
21
|
assert_response :success
|
22
|
-
|
22
|
+
|
23
23
|
assert assigns(:config_vars).include?(config_vars(:app_uri)),
|
24
24
|
"@config_vars doesn't have a database fixture"
|
25
25
|
assert assigns(:default_vars).map(&:first).
|
@@ -29,13 +29,13 @@ class ConfigVarsControllerApiTest < ActionController::TestCase
|
|
29
29
|
end
|
30
30
|
|
31
31
|
test "should get variable value" do
|
32
|
-
get :show, :
|
32
|
+
get :show, name: @config_var.to_param
|
33
33
|
assert_response :success
|
34
34
|
assert_equal @config_var.value, @response.body
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
test "edit with preset name and default value" do
|
38
|
-
get :edit, :
|
38
|
+
get :edit, name: 'config_vars.http_user'
|
39
39
|
assert_response :success
|
40
40
|
assert_equal 'config_vars.http_user', assigns(:config_var).name
|
41
41
|
assert_equal 'config', assigns(:config_var).value
|
@@ -44,7 +44,7 @@ class ConfigVarsControllerApiTest < ActionController::TestCase
|
|
44
44
|
test "should create config_var" do
|
45
45
|
attributes = @config_var.attributes.merge 'name' => 'other_uri'
|
46
46
|
assert_difference('ConfigVar.count') do
|
47
|
-
put :update, :
|
47
|
+
put :update, config_var: attributes
|
48
48
|
end
|
49
49
|
|
50
50
|
assert_redirected_to config_vars_url
|
@@ -52,27 +52,26 @@ class ConfigVarsControllerApiTest < ActionController::TestCase
|
|
52
52
|
end
|
53
53
|
|
54
54
|
test "should get edit" do
|
55
|
-
get :edit, :
|
55
|
+
get :edit, name: @config_var.to_param
|
56
56
|
assert_response :success
|
57
57
|
end
|
58
58
|
|
59
59
|
test "should update config_var" do
|
60
|
-
put :update, :
|
61
|
-
:config_var => @config_var.attributes
|
60
|
+
put :update, config_var: @config_var.attributes
|
62
61
|
assert_redirected_to config_vars_url
|
63
62
|
end
|
64
63
|
|
65
64
|
test "should destroy config_var" do
|
66
65
|
assert_difference('ConfigVar.count', -1) do
|
67
|
-
delete :destroy, :
|
66
|
+
delete :destroy, name: @config_var.to_param
|
68
67
|
end
|
69
68
|
|
70
69
|
assert_redirected_to config_vars_url
|
71
70
|
end
|
72
|
-
|
71
|
+
|
73
72
|
test "cannot access config vars without authentication" do
|
74
73
|
request.env.delete 'HTTP_AUTHORIZATION'
|
75
74
|
get :index
|
76
|
-
assert_response :unauthorized
|
75
|
+
assert_response :unauthorized
|
77
76
|
end
|
78
77
|
end
|
data/test/helpers/db_setup.rb
CHANGED
@@ -1,5 +1,17 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
case ENV['DB']
|
2
|
+
when /mysql/i
|
3
|
+
`mysql -u root -e "DROP DATABASE IF EXISTS plugin_dev; CREATE DATABASE plugin_dev;"`
|
4
|
+
ActiveRecord::Base.establish_connection adapter: 'mysql2',
|
5
|
+
database: 'plugin_dev', username: 'root', password: ''
|
6
|
+
when /pg/i
|
7
|
+
`psql -d postgres -c "DROP DATABASE IF EXISTS plugin_dev;"`
|
8
|
+
`psql -d postgres -c "CREATE DATABASE plugin_dev;"`
|
9
|
+
ActiveRecord::Base.establish_connection adapter: 'postgresql',
|
10
|
+
database: 'plugin_dev', username: ENV['USER'], password: ''
|
11
|
+
else
|
12
|
+
ActiveRecord::Base.establish_connection adapter: 'sqlite3',
|
13
|
+
database: ':memory:'
|
14
|
+
end
|
3
15
|
ActiveRecord::Base.configurations = true
|
4
16
|
|
5
17
|
ActiveRecord::Migration.verbose = false
|
@@ -11,11 +23,11 @@ require 'configvars_rails/generators/templates/config_var.rb'
|
|
11
23
|
# :nodoc: open TestCase to setup fixtures
|
12
24
|
class ActiveSupport::TestCase
|
13
25
|
include ActiveRecord::TestFixtures
|
14
|
-
|
26
|
+
|
15
27
|
self.fixture_path =
|
16
28
|
File.expand_path '../../../lib/configvars_rails/generators/templates',
|
17
29
|
__FILE__
|
18
|
-
|
30
|
+
|
19
31
|
self.use_transactional_fixtures = false
|
20
32
|
self.use_instantiated_fixtures = false
|
21
33
|
self.pre_loaded_fixtures = false
|
data/test/helpers/rails.rb
CHANGED
@@ -18,5 +18,11 @@ end
|
|
18
18
|
# For javascript_include_tag in the config_vars layout.
|
19
19
|
ActionController::Base.config.assets_dir = '.'
|
20
20
|
ActionController::Base.config.javascripts_dir = '.'
|
21
|
-
|
22
|
-
|
21
|
+
|
22
|
+
if ActionView::Helpers::AssetTagHelper.respond_to?(:register_javascript_expansion)
|
23
|
+
# Rails 3.
|
24
|
+
ActionView::Helpers::AssetTagHelper.
|
25
|
+
register_javascript_expansion(defaults: ['rails.js'])
|
26
|
+
else
|
27
|
+
# Rails 4 doesn't seem to need anything.
|
28
|
+
end
|
data/test/helpers/routes.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
# :nodoc: the routes used in all tests
|
2
2
|
class ActionController::TestCase
|
3
3
|
def setup_routes
|
4
|
-
|
4
|
+
if defined? ActionDispatch::Routing
|
5
|
+
# Rails 4.
|
6
|
+
@routes = ActionDispatch::Routing::RouteSet.new
|
7
|
+
else
|
8
|
+
# Rails 3.
|
9
|
+
@routes = ActionController::Routing::RouteSet.new
|
10
|
+
end
|
5
11
|
@routes.draw do
|
6
12
|
# NOTE: this route should be kept in sync with the config_vars template.
|
7
13
|
config_vars
|
@@ -9,6 +15,6 @@ class ActionController::TestCase
|
|
9
15
|
end
|
10
16
|
ApplicationController.send :include, @routes.url_helpers
|
11
17
|
end
|
12
|
-
|
18
|
+
|
13
19
|
setup :setup_routes
|
14
20
|
end
|
data/test/routes_test.rb
CHANGED
@@ -7,19 +7,18 @@ class RoutesTest < ActionController::TestCase
|
|
7
7
|
tests ConfigVarsController
|
8
8
|
|
9
9
|
test "config_vars routes" do
|
10
|
-
assert_routing({:
|
11
|
-
{:
|
12
|
-
assert_routing({:
|
13
|
-
{:
|
14
|
-
:
|
15
|
-
assert_routing({:
|
16
|
-
{:
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
:name => 'http.user'})
|
10
|
+
assert_routing({path: "/config_vars", method: :get},
|
11
|
+
{controller: 'config_vars', action: 'index'})
|
12
|
+
assert_routing({path: "/config_vars/http.user", method: :get},
|
13
|
+
{controller: 'config_vars', action: 'show',
|
14
|
+
name: 'http.user'})
|
15
|
+
assert_routing({path: "/config_vars", method: :put},
|
16
|
+
{controller: 'config_vars', action: 'update'})
|
17
|
+
assert_routing({path: "/config_vars/http.user", method: :delete},
|
18
|
+
{controller: 'config_vars', action: 'destroy',
|
19
|
+
name: 'http.user'})
|
20
|
+
assert_routing({path: "/config_vars/http.user/edit", method: :get},
|
21
|
+
{controller: 'config_vars', action: 'edit',
|
22
|
+
name: 'http.user'})
|
24
23
|
end
|
25
24
|
end
|
metadata
CHANGED
@@ -1,63 +1,103 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configvars_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.6.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Victor Costan
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-12-07 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rails
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 3.2.
|
19
|
+
version: 3.2.16
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.16
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: bundler
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.
|
33
|
+
version: 1.3.5
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.5
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: jeweler
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - '>='
|
42
46
|
- !ruby/object:Gem::Version
|
43
|
-
version: 1.8.
|
47
|
+
version: 1.8.8
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.8.8
|
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.14
|
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.14
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pg
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.17.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.17.0
|
47
83
|
- !ruby/object:Gem::Dependency
|
48
84
|
name: sqlite3
|
49
|
-
requirement:
|
50
|
-
none: false
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
51
86
|
requirements:
|
52
|
-
- -
|
87
|
+
- - '>='
|
53
88
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.3.
|
89
|
+
version: 1.3.8
|
55
90
|
type: :development
|
56
91
|
prerelease: false
|
57
|
-
version_requirements:
|
58
|
-
|
59
|
-
|
60
|
-
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.3.8
|
97
|
+
description: |-
|
98
|
+
This gem provides a model and simple controller for
|
99
|
+
storing global application configuration in a database. This allows the
|
100
|
+
configuration to change without source code modifications.
|
61
101
|
email: victor@costan.us
|
62
102
|
executables: []
|
63
103
|
extensions: []
|
@@ -66,8 +106,11 @@ extra_rdoc_files:
|
|
66
106
|
- README.rdoc
|
67
107
|
files:
|
68
108
|
- .project
|
109
|
+
- .travis.yml
|
69
110
|
- Gemfile
|
70
111
|
- Gemfile.lock
|
112
|
+
- Gemfile.rails3
|
113
|
+
- Gemfile.rails4
|
71
114
|
- LICENSE
|
72
115
|
- README.rdoc
|
73
116
|
- Rakefile
|
@@ -109,29 +152,25 @@ files:
|
|
109
152
|
homepage: http://github.com/pwnall/configvars_rails
|
110
153
|
licenses:
|
111
154
|
- MIT
|
155
|
+
metadata: {}
|
112
156
|
post_install_message:
|
113
157
|
rdoc_options: []
|
114
158
|
require_paths:
|
115
159
|
- lib
|
116
160
|
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
-
none: false
|
118
161
|
requirements:
|
119
|
-
- -
|
162
|
+
- - '>='
|
120
163
|
- !ruby/object:Gem::Version
|
121
164
|
version: '0'
|
122
|
-
segments:
|
123
|
-
- 0
|
124
|
-
hash: -1731949087483486988
|
125
165
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
-
none: false
|
127
166
|
requirements:
|
128
|
-
- -
|
167
|
+
- - '>='
|
129
168
|
- !ruby/object:Gem::Version
|
130
169
|
version: '0'
|
131
170
|
requirements: []
|
132
171
|
rubyforge_project:
|
133
|
-
rubygems_version: 1.
|
172
|
+
rubygems_version: 2.1.11
|
134
173
|
signing_key:
|
135
|
-
specification_version:
|
174
|
+
specification_version: 4
|
136
175
|
summary: Global configuration variables for Rails 3 applications.
|
137
176
|
test_files: []
|