camping 3.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  module Camping
2
- VERSION = "3.0.1"
2
+ VERSION = "3.1.0"
3
3
  def self.version
4
4
  VERSION
5
5
  end
@@ -724,7 +724,6 @@ module Camping
724
724
  #
725
725
  # See: https://github.com/rack/rack/blob/main/SPEC.rdoc
726
726
  def call(e)
727
- make_camp # TODO: Find a better, more consistent place for setting everything up.
728
727
  k,m,*a=X.D e["PATH_INFO"],e['REQUEST_METHOD'].downcase,e
729
728
  k.new(e,m,prx).service(*a).to_a
730
729
  rescue
@@ -752,8 +751,9 @@ module Camping
752
751
  def method_missing(m, c, *a)
753
752
  h = Hash === a[-1] ? a.pop : {}
754
753
  e = H[Rack::MockRequest.env_for('',h.delete(:env)||{})]
755
- # puts "method missing failure for controller: #{c}, method: #{m} "
756
754
  k = X.const_get(c).new(e,m.to_s,prx)
755
+ # rescue => error # : wrong number of arguments
756
+ # Campguide::make_sense error.message
757
757
  h.each { |i, v| k.send("#{i}=", v) }
758
758
  k.service(*a)
759
759
  end
@@ -914,6 +914,7 @@ module Camping
914
914
  # setup caller data
915
915
  sp = caller[0].split('`')[0].split(":")
916
916
  fl, ln, pr = sp[0], sp[1].to_i, nil
917
+ # ln = 0
917
918
 
918
919
  # Create the app
919
920
  Apps << a = eval(S.gsub(/Camping/,m.to_s), g, fl, ln)
data/lib/camping.rb CHANGED
@@ -66,7 +66,7 @@ k.meta_def(:urls){[A.(k,"#{c.to_s.scan(/.[^A-Z]*/).map(&N.method(:[]))*'/'}",p)]
66
66
  .respond_to?(:urls) || mu==true)};end end;I=R()end;X=Controllers
67
67
  class<<self;def make_camp;X.M prx;Apps.map(&:make_camp) end;def routes;(Apps.map(&:routes)<<X.v).flatten end
68
68
  def prx;@_prx||=CampTools.normalize_slashes(O[:url_prefix])end
69
- def call e;make_camp;k,m,*a=X.D e["PATH_INFO"],e['REQUEST_METHOD'].
69
+ def call e;k,m,*a=X.D e["PATH_INFO"],e['REQUEST_METHOD'].
70
70
  downcase,e;k.new(e,m,prx).service(*a).to_a;rescue;r500(:I,k,m,$!,:env=>e).to_a end
71
71
  def method_missing m,c,*a;h=Hash===a[-1]?a.pop : {};e=H[Rack::MockRequest.
72
72
  env_for('',h.delete(:env)||{})];k=X.const_get(c).new(e,m.to_s,prx);h.each{|i,v|
data/test/app_config.rb CHANGED
@@ -5,16 +5,14 @@ module Config end
5
5
 
6
6
  class Config::Test < TestCase
7
7
 
8
- def setup
8
+ def before_all
9
9
  write_config()
10
10
  Camping.goes :Config
11
11
  @options = Camping::Apps.select{|a| a.name == "Config" }.first.options
12
- super
13
12
  end
14
13
 
15
- def teardown
14
+ def after_all
16
15
  trash_config()
17
- super
18
16
  end
19
17
 
20
18
  def test_config
@@ -0,0 +1,82 @@
1
+ require 'test_helper'
2
+ require 'camping'
3
+ require 'camping/commands'
4
+
5
+ Camping.goes :Generator
6
+
7
+ class Generator::Test < TestCase
8
+
9
+ def app_name(string)
10
+ Camping::CommandsHelpers.app_name_from_input string
11
+ end
12
+
13
+ # the app_name_from_input method normalizes the input for the camping new command.
14
+ # making sure it works right is kinda important.
15
+ def test_app_name_from_input_method
16
+
17
+ # input is expected, a symbol camel cased
18
+ app_name(:AppApp) => {app_name:, snake_name:, camel_name:}
19
+ assert_equal :AppApp, app_name, "app_name was unexpected: #{app_name}"
20
+ assert_equal "app_app", snake_name, "snake_name was unexpected: #{snake_name}"
21
+ assert_equal "AppApp", camel_name, "camel_name was unexpected: #{camel_name}"
22
+
23
+ # input is un expected, a camel cased string
24
+ app_name("AppApp") => {app_name:, snake_name:, camel_name:}
25
+ assert_equal :AppApp, app_name, "app_name was unexpected: #{app_name}"
26
+ assert_equal "app_app", snake_name, "snake_name was unexpected: #{snake_name}"
27
+ assert_equal "AppApp", camel_name, "camel_name was unexpected: #{camel_name}"
28
+
29
+ # input is un unexpected snake cased string
30
+ app_name("app_app") => {app_name:, snake_name:, camel_name:}
31
+ assert_equal :AppApp, app_name, "app_name was unexpected: #{app_name}"
32
+ assert_equal "app_app", snake_name, "snake_name was unexpected: #{snake_name}"
33
+ assert_equal "AppApp", camel_name, "camel_name was unexpected: #{camel_name}"
34
+
35
+ # input is un unexpected snake cased symbol
36
+ app_name(:app_app) => {app_name:, snake_name:, camel_name:}
37
+ assert_equal :AppApp, app_name, "app_name was unexpected: #{app_name}"
38
+ assert_equal "app_app", snake_name, "snake_name was unexpected: #{snake_name}"
39
+ assert_equal "AppApp", camel_name, "camel_name was unexpected: #{camel_name}"
40
+
41
+ end
42
+
43
+ # Generates expected directory Structure
44
+ #
45
+ # Camping has an expected directory structure:
46
+ #
47
+ # .gitignore
48
+ # .ruby-version
49
+ # Gemfile
50
+ # Rakefile
51
+ # camp.rb
52
+ # config.kdl
53
+ # src/
54
+ # lib/
55
+ # public/
56
+ # test/
57
+ # apps/
58
+ #
59
+ # This test checks to make certain that the generator command creates this
60
+ # directory structure.
61
+ def test_app_generates_directory_structure
62
+ move_to_tmp
63
+ Camping::Commands.new_cmd
64
+
65
+ res, ignored = [Dir.glob('*').select {|f| !File.directory? f },
66
+ Dir.glob('*').select {|f| File.directory? f }], Dir.glob(".*")
67
+
68
+ assert res[0].include?('Gemfile'), "mising Gemfile"
69
+ assert res[0].include?('README.md'), "missing README.md"
70
+ assert res[0].include?('Rakefile'), "missing Rakefile"
71
+ assert res[0].include?('camp.rb'), "missing camp.rb"
72
+ assert res[0].include?('config.kdl'), "missing config.kdl"
73
+ assert res[1].include?('public'), "missing public folder."
74
+ assert res[1].include?('test'), "missing test folder."
75
+
76
+ assert ignored.include?('.gitignore'), ".gitignore is missing."
77
+ assert ignored.include?('.ruby-version'), ".ruby-version is missing."
78
+
79
+ leave_tmp
80
+ end
81
+
82
+ end
@@ -2,6 +2,13 @@ require 'test_helper'
2
2
  require 'camping'
3
3
  require 'camping/commands'
4
4
 
5
+ # The idea behind the inception stuff is that you can inherit settings
6
+ # templates, etc... from a Camping app and just... extend it.
7
+ # This is a tabled, but not abandoned idea. It became a little difficult
8
+ # to inherit all of these things, along with views, Models, etc... that's
9
+ # associated with a camping app. Getting this to work would mean a big
10
+ # rewrite of Camping's core, which is a no no.
11
+
5
12
  Camping.goes :Inception
6
13
  # Inception.goes :Leonardo
7
14
  # Leonardo.goes :Donatello
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+ require 'fileutils'
3
+ require 'camping/loader'
4
+
5
+ module Donuts end
6
+ module Loader end
7
+
8
+ # for Reloading stuff
9
+ module TestCaseLoaderToo
10
+ def loader
11
+ @loader ||= Camping::Loader.new(file)
12
+ end
13
+
14
+ def before_all
15
+ super
16
+ move_to_loader
17
+ loader.reload!
18
+ end
19
+
20
+ def after_all
21
+ leave_loader
22
+ super
23
+ end
24
+ end
25
+
26
+ class Donuts::Test < TestCase
27
+ include TestCaseLoaderToo
28
+ BASE = File.expand_path('../apps/loader/camp', __FILE__)
29
+ def file; BASE + '.rb' end
30
+
31
+ def test_that_our_apps_are_there
32
+ assert loader.apps.include?(:Donuts), "Donuts not found: #{loader.apps}"
33
+ assert loader.apps.include?(:Loader), "Loader not found: #{loader.apps}"
34
+ end
35
+
36
+ def test_output
37
+ # Checks that the view is overwritten successfully more than once.
38
+ get '/'
39
+ assert_body "chunky bacon", "Response is wrong in the loader."
40
+ assert_equal "text/html", last_response.headers['content-type']
41
+
42
+ # Checks that the view is not overwritten, because it's not reopened.
43
+ get '/post'
44
+ assert_body "_why", "Response is wrong in the loader."
45
+ assert_equal "text/html", last_response.headers['content-type']
46
+
47
+ # Checks that a downstream view is loaded properly.
48
+ get '/people'
49
+ assert_body "People are great am I right?", "Response is wrong in the loader."
50
+ assert_equal "text/html", last_response.headers['content-type']
51
+ end
52
+
53
+ end
data/test/app_sessions.rb CHANGED
@@ -44,8 +44,8 @@ class Sessions::Test < TestCase
44
44
  app.set :secret, "whateverloser"
45
45
  begin
46
46
  app.include Camping::Session
47
- rescue InsecureSecret => e
48
- message = "You're Session Secret is too short. Minimum length is 64."
47
+ rescue InsecureSecretError => e
48
+ message = "Your Session Secret is too short. Minimum length is 64."
49
49
  assert_equal(e.message, message, "You're session secret wasn't long enough.")
50
50
  end
51
51
 
@@ -54,11 +54,11 @@ class Sessions::Test < TestCase
54
54
  begin
55
55
  app.set :secret, "whateverloserwhateverloserwhateverloserwhateverloserwhateverloser"
56
56
  app.include Camping::Session
57
- rescue InsecureSecret => e
57
+ rescue InsecureSecretError => e
58
58
  message = e
59
59
  end
60
60
 
61
- assert_equal(e, message, "You're session secret wasn't long enough.")
61
+ assert_equal(e, message, "Your session secret wasn't long enough.")
62
62
  end
63
63
  end
64
64
 
@@ -0,0 +1,18 @@
1
+ module Donuts
2
+ module Controllers
3
+ class Index
4
+ def get
5
+ render :index
6
+ end
7
+ end
8
+ end
9
+
10
+ # how to add a layout to every page
11
+ module Views
12
+
13
+ def index
14
+ "chunky bacon"
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module Donuts
2
+ module Controllers
3
+ class Index
4
+ def get
5
+ "We've got lots of donuts!"
6
+ end
7
+ end
8
+
9
+ class People
10
+ def get
11
+ "People are great am I right?"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ require 'camping'
2
+
3
+ Camping.goes :Loader
4
+
5
+ $LOAD_PATH << File.dirname(__FILE__)
6
+
7
+ Camping.goes :Donuts
8
+
9
+ module Donuts
10
+ module Controllers
11
+ class Index
12
+ def get
13
+ render :index
14
+ end
15
+ end
16
+ class Post
17
+ def get
18
+ render :post
19
+ end
20
+ end
21
+ end
22
+
23
+ # how to add a layout to every page
24
+ module Views
25
+
26
+ def index
27
+ "_why"
28
+ end
29
+
30
+ def post
31
+ "_why"
32
+ end
33
+
34
+ end
35
+ end
@@ -1,5 +1,5 @@
1
1
  $LOAD_PATH << File.dirname(__FILE__) + '/../'
2
+ $LOAD_PATH << File.dirname(__FILE__) + '/'
2
3
 
3
4
  require 'reloader'
4
5
  run Reloader
5
-
@@ -1,2 +1 @@
1
1
  $counter += 1
2
-
@@ -3,5 +3,4 @@ require 'camping'
3
3
  Camping.goes :Reloader
4
4
 
5
5
  $LOAD_PATH << File.dirname(__FILE__)
6
- require 'reloader/reload_me'
7
-
6
+ require 'reload_me'
@@ -0,0 +1,78 @@
1
+ require_relative 'test_helper'
2
+ require 'fileutils'
3
+ require 'camping/loader'
4
+
5
+ $counter = 0
6
+
7
+ # for Reloading stuff
8
+ module TestCaseLoader
9
+
10
+ def loader
11
+ @loader ||= Camping::Loader.new(file)
12
+ end
13
+
14
+ def before_all
15
+ super
16
+ move_to_reloader
17
+ loader.reload!
18
+ assert Object.const_defined?(:Reloader), "Reloader didn't load app"
19
+ # puts "before_all called"
20
+ end
21
+
22
+ def after_all
23
+ # puts "after_all called"
24
+ assert Object.const_defined?(:Reloader), "Test removed app"
25
+ loader.remove_constants
26
+ # breaks in CI for some reason.
27
+ # assert !Object.const_defined?(:Reloader), "Loader didn't remove app"
28
+ leave_reloader
29
+ super
30
+ end
31
+
32
+ end
33
+
34
+ class TestConfigRu < TestCase
35
+ include TestCaseLoader
36
+
37
+ BASE = File.expand_path('../apps/reloader', __FILE__)
38
+ def file; BASE + '/config.ru' end
39
+
40
+ def setup
41
+ super
42
+ $counter = 0
43
+ loader.reload!
44
+ # puts "setup called"
45
+ end
46
+
47
+ def test_counter
48
+ assert_equal 1, $counter
49
+ end
50
+
51
+ def test_forced_reload
52
+ loader.reload!
53
+ assert_equal 2, $counter
54
+ end
55
+
56
+ def test_that_touch_was_touched
57
+ FileUtils.touch(BASE + '/reloader.rb')
58
+ assert_equal 1, $counter
59
+ end
60
+
61
+ def test_mtime_reload
62
+ loader.reload
63
+ assert_equal 1, $counter
64
+
65
+ FileUtils.touch(BASE + '/reloader.rb')
66
+ loader.reload
67
+ assert_equal 2, $counter
68
+
69
+ FileUtils.touch(BASE + '/reload_me.rb')
70
+ loader.reload
71
+ assert_equal 3, $counter
72
+ end
73
+
74
+ def test_name
75
+ assert_equal Reloader, loader.apps[:reloader]
76
+ end
77
+
78
+ end
@@ -0,0 +1,81 @@
1
+ require_relative 'test_helper'
2
+ require 'fileutils'
3
+ require 'camping/loader'
4
+
5
+ $counter = 0
6
+
7
+ # for Reloading stuff
8
+ module TestCaseLoader
9
+
10
+ def loader
11
+ @loader ||= Camping::Loader.new(file)
12
+ end
13
+
14
+ def before_all
15
+ super
16
+ move_to_reloader
17
+ loader.reload!
18
+ assert Object.const_defined?(:Reloader), "Reloader didn't load app"
19
+ # puts "before_all called"
20
+ end
21
+
22
+ def after_all
23
+ # puts "after_all called"
24
+ assert Object.const_defined?(:Reloader), "Test removed app"
25
+ loader.remove_constants
26
+ assert !Object.const_defined?(:Reloader), "Loader didn't remove app"
27
+ leave_reloader
28
+ super
29
+ end
30
+
31
+ end
32
+
33
+ class TestLoader < TestCase
34
+ include TestCaseLoader
35
+
36
+ BASE = File.expand_path('../apps/reloader', __FILE__)
37
+ def file; BASE + '/reloader.rb' end
38
+
39
+ def setup
40
+ super
41
+ $counter = 0
42
+ loader.reload!
43
+ # puts "setup called"
44
+ end
45
+
46
+ def test_counter
47
+ assert_equal 1, $counter
48
+ end
49
+
50
+ def test_forced_reload
51
+ loader.reload!
52
+ assert_equal 2, $counter
53
+ end
54
+
55
+ def test_that_touch_was_touched
56
+ FileUtils.touch(BASE + '/reloader.rb')
57
+ assert_equal 1, $counter
58
+ end
59
+
60
+ def test_mtime_reload
61
+ loader.reload
62
+ assert_equal 1, $counter
63
+
64
+ FileUtils.touch(BASE + '/reloader.rb')
65
+ loader.reload
66
+ assert_equal 2, $counter
67
+
68
+ FileUtils.touch(BASE + '/reload_me.rb')
69
+ loader.reload
70
+ assert_equal 3, $counter
71
+ end
72
+ end
73
+
74
+ # class TestConfigRu < TestLoader
75
+ # BASE = File.expand_path('../apps/reloader', __FILE__)
76
+ # def file; BASE + '/config.ru' end
77
+
78
+ # def test_name
79
+ # assert_equal Reloader, loader.apps[:reloader]
80
+ # end
81
+ # end
data/test/test_helper.rb CHANGED
@@ -14,7 +14,8 @@ end
14
14
 
15
15
  require 'minitest/autorun'
16
16
  require 'rack/test'
17
- require "minitest/reporters"
17
+ require 'minitest/reporters'
18
+ require 'minitest/hooks'
18
19
  Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(:color => true)]
19
20
 
20
21
 
@@ -32,6 +33,40 @@ module CommandLineCommands
32
33
  `rm -rf test/tmp` if File.exist?('test/tmp')
33
34
  end
34
35
 
36
+ # reloader helpers:
37
+ # move_to_apps
38
+ # moves to the apps directory in /test
39
+ def move_to_reloader
40
+ @original_dir = Dir.pwd
41
+ Dir.chdir "test"
42
+ Dir.chdir "apps"
43
+ Dir.chdir "reloader"
44
+ Dir.mkdir("apps") unless Dir.exist?("apps")
45
+ Dir.mkdir("lib") unless Dir.exist?("lib")
46
+ end
47
+
48
+ # deletes the temporary directories found in the /apps directory for reloader testing.
49
+ def leave_reloader
50
+ Dir.chdir @original_dir
51
+ `rm -rf test/apps/reloader/apps` if File.exist?('test/apps/reloader/apps')
52
+ `rm -rf test/apps/reloader/lib` if File.exist?('test/apps/reloader/lib')
53
+ end
54
+
55
+ # Moves to the loader directory
56
+ def move_to_loader
57
+ @original_dir = Dir.pwd
58
+ Dir.chdir "test"
59
+ Dir.chdir "apps"
60
+ Dir.chdir "loader"
61
+ Dir.mkdir("apps") unless Dir.exist?("apps")
62
+ Dir.mkdir("lib") unless Dir.exist?("lib")
63
+ end
64
+
65
+ # deletes the temporary directories found in the /apps directory for reloader testing.
66
+ def leave_loader
67
+ Dir.chdir @original_dir
68
+ end
69
+
35
70
  def write(file, content)
36
71
  raise "cannot write nil" unless file
37
72
  file = tmp_file(file)
@@ -70,6 +105,7 @@ end
70
105
  class TestCase < MiniTest::Test
71
106
  include Rack::Test::Methods
72
107
  include CommandLineCommands
108
+ include Minitest::Hooks
73
109
 
74
110
  def self.inherited(mod)
75
111
  mod.app = Object.const_get(mod.to_s[/\w+/])
@@ -80,6 +116,11 @@ class TestCase < MiniTest::Test
80
116
  attr_accessor :app
81
117
  end
82
118
 
119
+ def setup
120
+ super
121
+ Camping.make_camp
122
+ end
123
+
83
124
  def body() last_response.body end
84
125
  def app() self.class.app end
85
126
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camping
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - why the lucky stiff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-18 00:00:00.000000000 Z
11
+ date: 2023-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mab
@@ -153,14 +153,15 @@ files:
153
153
  - lib/camping-unabridged.rb
154
154
  - lib/camping.rb
155
155
  - lib/camping/ar.rb
156
+ - lib/camping/campguide.rb
156
157
  - lib/camping/commands.rb
157
158
  - lib/camping/gear/filters.rb
158
159
  - lib/camping/gear/inspection.rb
159
160
  - lib/camping/gear/kuddly.rb
160
161
  - lib/camping/gear/nancy.rb
162
+ - lib/camping/loader.rb
161
163
  - lib/camping/loads.rb
162
164
  - lib/camping/mab.rb
163
- - lib/camping/reloader.rb
164
165
  - lib/camping/server.rb
165
166
  - lib/camping/session.rb
166
167
  - lib/camping/template.rb
@@ -172,29 +173,35 @@ files:
172
173
  - test/app_config.rb
173
174
  - test/app_cookies.rb
174
175
  - test/app_file.rb
176
+ - test/app_generator.rb
175
177
  - test/app_goes_meta.rb
176
178
  - test/app_helpers.rb
177
179
  - test/app_inception.rb
178
180
  - test/app_inline_templates.rb
181
+ - test/app_loader.rb
179
182
  - test/app_markup.rb
180
183
  - test/app_migrations.rb
181
184
  - test/app_partials.rb
182
185
  - test/app_prefixed.rb
183
- - test/app_reloader.rb
184
186
  - test/app_route_generating.rb
185
187
  - test/app_sessions.rb
186
188
  - test/app_simple.rb
187
189
  - test/apps/env_debug.rb
188
190
  - test/apps/forms.rb
189
191
  - test/apps/forward_to_other_controller.rb
192
+ - test/apps/loader/apps/donuts.rb
193
+ - test/apps/loader/apps/donuts/controllers/index.rb
194
+ - test/apps/loader/camp.rb
190
195
  - test/apps/migrations.rb
191
196
  - test/apps/misc.rb
192
- - test/apps/reloader.rb
193
197
  - test/apps/reloader/config.ru
194
198
  - test/apps/reloader/reload_me.rb
199
+ - test/apps/reloader/reloader.rb
195
200
  - test/apps/reloader_indirect.rb
196
201
  - test/apps/sessions.rb
202
+ - test/config_reloader.rb
197
203
  - test/gear/gear_nancy.rb
204
+ - test/reload_reloader.rb
198
205
  - test/test_helper.rb
199
206
  homepage: http://camping.rubyforge.org/
200
207
  licenses: []
@@ -222,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
229
  - !ruby/object:Gem::Version
223
230
  version: '0'
224
231
  requirements: []
225
- rubygems_version: 3.4.10
232
+ rubygems_version: 3.4.12
226
233
  signing_key:
227
234
  specification_version: 4
228
235
  summary: micro mighty websites for anyone