rs_yettings 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/README.md +186 -0
  2. data/Rakefile +38 -0
  3. data/lib/tasks/yettings.rake +17 -0
  4. data/lib/yettings.rb +79 -0
  5. data/lib/yettings/base.rb +41 -0
  6. data/lib/yettings/encryption.rb +124 -0
  7. data/lib/yettings/railtie.rb +15 -0
  8. data/lib/yettings/version.rb +3 -0
  9. data/spec/dummy/Guardfile +228 -0
  10. data/spec/dummy/README.rdoc +261 -0
  11. data/spec/dummy/Rakefile +7 -0
  12. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  13. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  14. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  15. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  16. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  17. data/spec/dummy/config.ru +4 -0
  18. data/spec/dummy/config/application.rb +59 -0
  19. data/spec/dummy/config/boot.rb +10 -0
  20. data/spec/dummy/config/database.yml +25 -0
  21. data/spec/dummy/config/environment.rb +5 -0
  22. data/spec/dummy/config/environments/development.rb +37 -0
  23. data/spec/dummy/config/environments/production.rb +67 -0
  24. data/spec/dummy/config/environments/test.rb +37 -0
  25. data/spec/dummy/config/ignored.yml +17 -0
  26. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  27. data/spec/dummy/config/initializers/inflections.rb +15 -0
  28. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  29. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  30. data/spec/dummy/config/initializers/session_store.rb +8 -0
  31. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  32. data/spec/dummy/config/locales/en.yml +5 -0
  33. data/spec/dummy/config/routes.rb +58 -0
  34. data/spec/dummy/config/yetting.yml +17 -0
  35. data/spec/dummy/config/yetting.yml.pub +0 -0
  36. data/spec/dummy/config/yettings/blank.yml +0 -0
  37. data/spec/dummy/config/yettings/defaults.yml +6 -0
  38. data/spec/dummy/config/yettings/hendrix.yml +11 -0
  39. data/spec/dummy/config/yettings/jimi.yml +11 -0
  40. data/spec/dummy/config/yettings/secret.yml.pub +1 -0
  41. data/spec/dummy/db/test.sqlite3 +0 -0
  42. data/spec/dummy/log/development.log +1 -0
  43. data/spec/dummy/log/test.log +141 -0
  44. data/spec/dummy/public/404.html +26 -0
  45. data/spec/dummy/public/422.html +26 -0
  46. data/spec/dummy/public/500.html +25 -0
  47. data/spec/dummy/public/favicon.ico +0 -0
  48. data/spec/dummy/script/rails +6 -0
  49. data/spec/spec_helper.rb +28 -0
  50. data/spec/yettings/base_spec.rb +66 -0
  51. data/spec/yettings/encryption_spec.rb +104 -0
  52. data/spec/yettings_spec.rb +90 -0
  53. metadata +320 -0
@@ -0,0 +1,17 @@
1
+ defaults: &defaults
2
+ yetting1: what
3
+ yetting2: 999
4
+ yetting3: <%= "this is erb " %>
5
+ yetting4:
6
+ - element1
7
+ - element2
8
+
9
+ development:
10
+ <<: *defaults
11
+ yetting1: override for dev
12
+
13
+ test:
14
+ <<: *defaults
15
+
16
+ production:
17
+ <<: *defaults
File without changes
File without changes
@@ -0,0 +1,6 @@
1
+ defaults:
2
+ yetting1: default value
3
+ yetting2: default value
4
+
5
+ test:
6
+ yetting2: test value
@@ -0,0 +1,11 @@
1
+ defaults: &defaults
2
+ yetting1: jimi
3
+
4
+ development:
5
+ <<: *defaults
6
+
7
+ test:
8
+ <<: *defaults
9
+
10
+ production:
11
+ <<: *defaults
@@ -0,0 +1,11 @@
1
+ defaults: &defaults
2
+ yetting1: hendrix
3
+
4
+ development:
5
+ <<: *defaults
6
+
7
+ test:
8
+ <<: *defaults
9
+
10
+ production:
11
+ <<: *defaults
@@ -0,0 +1 @@
1
+ HOoHbzGX6mUJA7TNJsxTum2yrLDzyFJRkqE24/G7zdMYEQWrJ3jKS4PYoJodWwM1yqPLvgq7IzgNnXVq5AJPoSagWUWZwgS2Xpw1CgiwY+LU1BNXMfa1iSy3UVAzQ1UQeoDlw9WgjH8QL/ZA/GiqFrx1bzxD/xgFGEj5Y4AqqYkoSNqTNTLR0JRYvYNLYmbEFSt0Lj7hTZXVLVkF0i4ivBxUkDceeO+iSoEn8fPkMfS2SDL+uNMJE5SKu7RC3Zj+zroKQTpGfFPX9vqzSxasrznf9fKGqZUAsCk3G7BvgYU/TA8l9EtA2HxM7GquXtEWP5wlLut1jDCb5ZfqaFiGYiUmz0dG2HjEzl7znprgbqlrY/MyYw6eDnRuCaErAVWyaOHbuRsWd151YlqXXsNEdQCO5u0np+ynztcpLDOanzyUaOnHucVizjTkuFlddmko//VdB3G3YSRgFNjuDZzlxtZEpHq1yrRooCo8yIyMhRW+ZdEO5ANDWYszpjqJtnMRJAi8j6QtttxQoirw+chbCjG7hflzqUhqS6w79ax/luB9oGM0zQKJD4LYqxfw4P1Uut6Af3SfNh5JDBE3k0MP1r47pj0g2mZL5dlGVQwD8Ww=
File without changes
@@ -0,0 +1 @@
1
+ Connecting to database specified by database.yml
@@ -0,0 +1,141 @@
1
+ Connecting to database specified by database.yml
2
+  (0.3ms) begin transaction
3
+  (0.1ms) rollback transaction
4
+  (0.1ms) begin transaction
5
+  (0.1ms) rollback transaction
6
+  (0.1ms) begin transaction
7
+  (0.0ms) rollback transaction
8
+  (0.1ms) begin transaction
9
+  (0.1ms) rollback transaction
10
+  (0.1ms) begin transaction
11
+  (0.1ms) rollback transaction
12
+  (0.1ms) begin transaction
13
+  (0.1ms) rollback transaction
14
+  (0.1ms) begin transaction
15
+  (0.1ms) rollback transaction
16
+  (0.1ms) begin transaction
17
+  (0.1ms) rollback transaction
18
+  (0.1ms) begin transaction
19
+  (0.1ms) rollback transaction
20
+  (0.1ms) begin transaction
21
+  (0.1ms) rollback transaction
22
+  (0.1ms) begin transaction
23
+  (0.0ms) rollback transaction
24
+  (0.1ms) begin transaction
25
+  (0.1ms) rollback transaction
26
+  (0.1ms) begin transaction
27
+  (0.0ms) rollback transaction
28
+  (0.0ms) begin transaction
29
+  (0.1ms) rollback transaction
30
+  (0.1ms) begin transaction
31
+  (0.1ms) rollback transaction
32
+  (0.1ms) begin transaction
33
+  (0.1ms) rollback transaction
34
+  (0.1ms) begin transaction
35
+  (0.0ms) rollback transaction
36
+  (0.0ms) begin transaction
37
+  (0.0ms) rollback transaction
38
+  (0.0ms) begin transaction
39
+  (0.1ms) rollback transaction
40
+  (0.1ms) begin transaction
41
+  (0.0ms) rollback transaction
42
+  (0.0ms) begin transaction
43
+  (0.0ms) rollback transaction
44
+  (0.1ms) begin transaction
45
+  (0.0ms) rollback transaction
46
+  (0.1ms) begin transaction
47
+  (0.1ms) rollback transaction
48
+ Connecting to database specified by database.yml
49
+  (0.3ms) begin transaction
50
+  (0.1ms) rollback transaction
51
+  (0.1ms) begin transaction
52
+  (0.0ms) rollback transaction
53
+  (0.0ms) begin transaction
54
+  (0.0ms) rollback transaction
55
+  (0.0ms) begin transaction
56
+  (0.1ms) rollback transaction
57
+  (0.1ms) begin transaction
58
+  (0.0ms) rollback transaction
59
+  (0.1ms) begin transaction
60
+  (0.0ms) rollback transaction
61
+  (0.0ms) begin transaction
62
+  (0.0ms) rollback transaction
63
+  (0.0ms) begin transaction
64
+  (0.1ms) rollback transaction
65
+  (0.1ms) begin transaction
66
+  (0.1ms) rollback transaction
67
+  (0.1ms) begin transaction
68
+  (0.1ms) rollback transaction
69
+  (0.1ms) begin transaction
70
+  (0.0ms) rollback transaction
71
+  (0.1ms) begin transaction
72
+  (0.1ms) rollback transaction
73
+  (0.1ms) begin transaction
74
+  (0.0ms) rollback transaction
75
+  (0.1ms) begin transaction
76
+  (0.1ms) rollback transaction
77
+  (0.1ms) begin transaction
78
+  (0.1ms) rollback transaction
79
+  (0.1ms) begin transaction
80
+  (0.1ms) rollback transaction
81
+  (0.1ms) begin transaction
82
+  (0.1ms) rollback transaction
83
+  (0.1ms) begin transaction
84
+  (0.0ms) rollback transaction
85
+  (0.1ms) begin transaction
86
+  (0.1ms) rollback transaction
87
+  (0.1ms) begin transaction
88
+  (0.0ms) rollback transaction
89
+  (0.0ms) begin transaction
90
+  (0.0ms) rollback transaction
91
+  (0.1ms) begin transaction
92
+  (0.0ms) rollback transaction
93
+  (0.1ms) begin transaction
94
+  (0.1ms) rollback transaction
95
+ Connecting to database specified by database.yml
96
+  (0.4ms) begin transaction
97
+  (0.1ms) rollback transaction
98
+  (0.1ms) begin transaction
99
+  (0.1ms) rollback transaction
100
+  (0.1ms) begin transaction
101
+  (0.1ms) rollback transaction
102
+  (0.1ms) begin transaction
103
+  (0.1ms) rollback transaction
104
+  (0.1ms) begin transaction
105
+  (0.0ms) rollback transaction
106
+  (0.1ms) begin transaction
107
+  (0.0ms) rollback transaction
108
+  (0.0ms) begin transaction
109
+  (0.0ms) rollback transaction
110
+  (0.0ms) begin transaction
111
+  (0.0ms) rollback transaction
112
+  (0.0ms) begin transaction
113
+  (0.1ms) rollback transaction
114
+  (0.1ms) begin transaction
115
+  (0.1ms) rollback transaction
116
+  (0.1ms) begin transaction
117
+  (0.1ms) rollback transaction
118
+  (0.0ms) begin transaction
119
+  (0.1ms) rollback transaction
120
+  (0.1ms) begin transaction
121
+  (0.0ms) rollback transaction
122
+  (0.0ms) begin transaction
123
+  (0.1ms) rollback transaction
124
+  (0.1ms) begin transaction
125
+  (0.1ms) rollback transaction
126
+  (0.1ms) begin transaction
127
+  (0.1ms) rollback transaction
128
+  (0.1ms) begin transaction
129
+  (0.1ms) rollback transaction
130
+  (0.1ms) begin transaction
131
+  (0.1ms) rollback transaction
132
+  (0.1ms) begin transaction
133
+  (0.1ms) rollback transaction
134
+  (0.1ms) begin transaction
135
+  (0.1ms) rollback transaction
136
+  (0.1ms) begin transaction
137
+  (0.1ms) rollback transaction
138
+  (0.1ms) begin transaction
139
+  (0.0ms) rollback transaction
140
+  (0.1ms) begin transaction
141
+  (0.0ms) rollback transaction
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,28 @@
1
+ require 'spork'
2
+
3
+ Spork.prefork do
4
+ require 'simplecov'
5
+ SimpleCov.start do
6
+ add_filter "/spec/"
7
+ end
8
+
9
+ ENV["RAILS_ENV"] ||= 'test'
10
+ require File.expand_path('../dummy/config/environment', __FILE__)
11
+ require 'rspec/rails'
12
+ require 'rspec/autorun'
13
+ require 'factory_girl'
14
+ require "shoulda-matchers"
15
+
16
+ Dir[Rails.root.join("../spec/support/**/*.rb")].each {|f| require f }
17
+
18
+ RSpec.configure do |config|
19
+ config.mock_with :rspec
20
+ config.use_transactional_fixtures = true
21
+ config.filter_run_excluding :external => true
22
+ config.infer_base_class_for_anonymous_controllers = false
23
+ end
24
+ end
25
+
26
+ Spork.each_run do
27
+ FactoryGirl.reload
28
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yettings::Base do
4
+ YETTINGS_DIR = "#{Rails.root}/config/yettings"
5
+ YETTING_FILE = "#{Rails.root}/config/yetting.yml"
6
+ BLANK_YETTING_FILE = "#{Rails.root}/config/yettings/blank.yml"
7
+
8
+ subject { Class.new Yettings::Base }
9
+
10
+ describe ".load_yml_erb" do
11
+
12
+ it "should load the yml and return hash" do
13
+ yml_erb = File.read YETTING_FILE
14
+ expected = {"yetting1" => "what",
15
+ "yetting2" => 999,
16
+ "yetting3" => "this is erb",
17
+ "yetting4" => ["element1", "element2"]}
18
+ subject.load_yml_erb(yml_erb).should eq expected
19
+ end
20
+
21
+ it "should apply default settings to all environments" do
22
+ yml_erb = File.read "#{YETTINGS_DIR}/defaults.yml"
23
+ subject.load_yml_erb(yml_erb)
24
+ subject.yetting1.should eq 'default value'
25
+ end
26
+
27
+ it "should override default settings specific to environment" do
28
+ yml_erb = File.read "#{YETTINGS_DIR}/defaults.yml"
29
+ subject.load_yml_erb(yml_erb)
30
+ subject.yetting2.should eq 'test value'
31
+ end
32
+ end
33
+
34
+ describe ".method_missing" do
35
+ it "should issue a warning for method_missing" do
36
+ begin
37
+ subject.whatwhat
38
+ rescue => e
39
+ e.should be_kind_of Yettings::Base::UndefinedYettingError
40
+ e.message.should =~ /whatwhat is not defined in /
41
+ end
42
+ end
43
+ end
44
+
45
+ describe ".define_methods" do
46
+ it "defines methods for a hash" do
47
+ hash = {:method1 => "val1", :method2 => "val2"}
48
+ subject.define_methods(hash)
49
+ subject.method1.should eq "val1"
50
+ subject.method2.should eq "val2"
51
+ end
52
+ end
53
+
54
+ describe ".build_hash" do
55
+ it "returns blank hash for empty yml file" do
56
+ expected = {}
57
+ subject.build_hash("").should eq expected
58
+ end
59
+
60
+ it "returns hash for non-blank yaml file" do
61
+ yml = File.read "#{YETTINGS_DIR}/defaults.yml"
62
+ expected = {"defaults"=>{"yetting1"=>"default value", "yetting2"=>"default value"}, "test"=>{"yetting2"=>"test value"}}
63
+ subject.build_hash(yml).should eq expected
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,104 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yettings::Encryption do
4
+ YETTINGS_DIR = "#{Rails.root}/config/yettings"
5
+ YETTING_FILE = "#{Rails.root}/config/yetting.yml"
6
+ SECRET_YETTING_FILE = "#{Rails.root}/config/yettings/.private/secret2.yml"
7
+ SECRET_YETTING_PUB_FILE = "#{Rails.root}/config/yettings/secret2.yml.pub"
8
+ BLANK_YETTING_FILE = "#{Rails.root}/config/yettings/blank.yml"
9
+
10
+ let(:default_yml){ File.read "#{YETTINGS_DIR}/defaults.yml" }
11
+ let(:blank_yml){ "" }
12
+
13
+ describe ".decrypt_string" do
14
+ it "decrypts the string in binary" do
15
+ str = "This is a private string"
16
+ encrypted = Yettings.encrypt_string(str)
17
+ Yettings.decrypt_string(encrypted).should eq str
18
+ end
19
+ end
20
+
21
+ describe ".encrypt_string" do
22
+ it "encrypts the string in binary" do
23
+ str = "This is a private string"
24
+ Yettings.encrypt_string(str).equals_without_encryption(str).should be false
25
+ enc = Yettings.encrypt_string(str)
26
+ Yettings.decrypt_string(enc).should eq str
27
+ end
28
+ end
29
+
30
+ describe ".encrypt_file" do
31
+ before(:each) do
32
+ File.delete(SECRET_YETTING_PUB_FILE) if File.exists?(SECRET_YETTING_PUB_FILE)
33
+ end
34
+
35
+ after(:each) do
36
+ File.delete(SECRET_YETTING_PUB_FILE) if File.exists?(SECRET_YETTING_PUB_FILE)
37
+ end
38
+
39
+ it "returns nil if the private key is nil" do
40
+ Yettings.stub(:private_key => nil)
41
+ Yettings.encrypt_file(YETTING_FILE).should eq nil
42
+ end
43
+
44
+ it "returns nil check_overwrite is false" do
45
+ Yettings.stub(:check_overwrite => false)
46
+ Yettings.encrypt_file(YETTING_FILE).should eq nil
47
+ end
48
+
49
+ it "writes to file if private key is available and check_overwrite passes" do
50
+ Yettings.stub(:check_overwrite => true)
51
+ Yettings.encrypt_file(SECRET_YETTING_FILE)
52
+ File.exists?(SECRET_YETTING_PUB_FILE)
53
+ end
54
+ end
55
+
56
+ describe ".decrypt_file" do
57
+ pending
58
+ end
59
+
60
+ describe ".encrypt_files!" do
61
+ pending
62
+ end
63
+
64
+ describe ".decrypt_files!" do
65
+ pending
66
+ end
67
+
68
+ describe ".encrypt_files!" do
69
+ pending
70
+ end
71
+
72
+ describe ".check_overwrite" do
73
+ pending
74
+ end
75
+
76
+ describe ".private_path" do
77
+ pending
78
+ end
79
+
80
+ describe ".public_path" do
81
+ pending
82
+ end
83
+
84
+ describe ".public_key" do
85
+ pending
86
+ end
87
+
88
+ describe ".private_key" do
89
+ pending
90
+ end
91
+
92
+ describe ".load_key" do
93
+ pending
94
+ end
95
+
96
+ describe ".key_path" do
97
+ pending
98
+ end
99
+
100
+ describe ".gen_keys" do
101
+ pending
102
+ end
103
+
104
+ end