force_format 0.0.6 → 0.0.7

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.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +31 -0
  4. data/Appraisals +7 -0
  5. data/Gemfile +0 -3
  6. data/README.md +69 -24
  7. data/Rakefile +4 -0
  8. data/force_format.gemspec +2 -1
  9. data/gemfiles/3.2.gemfile +8 -0
  10. data/gemfiles/3.2.gemfile.lock +128 -0
  11. data/gemfiles/4.0.gemfile +8 -0
  12. data/gemfiles/4.0.gemfile.lock +123 -0
  13. data/lib/force_format/{controller_access.rb → controller.rb} +4 -3
  14. data/lib/force_format/errors.rb +4 -1
  15. data/lib/force_format/railtie.rb +4 -4
  16. data/lib/force_format/version.rb +1 -1
  17. data/lib/force_format/{view_patch.rb → view.rb} +1 -1
  18. data/spec/array_options_spec.rb +109 -0
  19. data/spec/{dummy → dummy3.2}/README.rdoc +0 -0
  20. data/spec/{dummy → dummy3.2}/Rakefile +0 -0
  21. data/spec/{dummy → dummy3.2}/app/assets/javascripts/application.js +0 -0
  22. data/spec/{dummy → dummy3.2}/app/assets/stylesheets/application.css +0 -0
  23. data/spec/{dummy → dummy3.2}/app/controllers/application_controller.rb +0 -0
  24. data/spec/{dummy → dummy3.2}/app/controllers/pages_controller.rb +0 -0
  25. data/spec/{dummy → dummy3.2}/app/helpers/application_helper.rb +0 -0
  26. data/spec/{dummy → dummy3.2}/app/mailers/.gitkeep +0 -0
  27. data/spec/{dummy → dummy3.2}/app/models/.gitkeep +0 -0
  28. data/spec/{dummy → dummy3.2}/app/views/layouts/application.html.erb +0 -0
  29. data/spec/{dummy → dummy3.2}/app/views/pages/index.html.erb +0 -0
  30. data/spec/{dummy → dummy3.2}/app/views/pages/with_html.html.erb +0 -0
  31. data/spec/{dummy → dummy3.2}/app/views/pages/with_html_js.html.erb +0 -0
  32. data/spec/{dummy → dummy3.2}/app/views/pages/with_html_js.js.erb +0 -0
  33. data/spec/{dummy → dummy3.2}/app/views/pages/with_js.js.erb +0 -0
  34. data/spec/{dummy → dummy3.2}/app/views/pages/with_json.json.erb +0 -0
  35. data/spec/{dummy → dummy3.2}/app/views/pages/with_xml.xml.erb +0 -0
  36. data/spec/{dummy → dummy3.2}/config/application.rb +0 -0
  37. data/spec/{dummy → dummy3.2}/config/boot.rb +0 -0
  38. data/spec/{dummy → dummy3.2}/config/database.yml +0 -0
  39. data/spec/{dummy → dummy3.2}/config/environment.rb +0 -0
  40. data/spec/{dummy → dummy3.2}/config/environments/development.rb +0 -0
  41. data/spec/{dummy → dummy3.2}/config/environments/production.rb +0 -0
  42. data/spec/{dummy → dummy3.2}/config/environments/test.rb +0 -0
  43. data/spec/{dummy → dummy3.2}/config/initializers/backtrace_silencers.rb +0 -0
  44. data/spec/{dummy → dummy3.2}/config/initializers/inflections.rb +0 -0
  45. data/spec/{dummy → dummy3.2}/config/initializers/mime_types.rb +0 -0
  46. data/spec/{dummy → dummy3.2}/config/initializers/secret_token.rb +0 -0
  47. data/spec/{dummy → dummy3.2}/config/initializers/session_store.rb +0 -0
  48. data/spec/{dummy → dummy3.2}/config/initializers/wrap_parameters.rb +0 -0
  49. data/spec/{dummy → dummy3.2}/config/locales/en.yml +0 -0
  50. data/spec/{dummy → dummy3.2}/config/routes.rb +0 -0
  51. data/spec/{dummy → dummy3.2}/config.ru +0 -0
  52. data/spec/{dummy/lib/assets/.gitkeep → dummy3.2/db/test.sqlite3} +0 -0
  53. data/spec/{dummy/log → dummy3.2/lib/assets}/.gitkeep +0 -0
  54. data/spec/{dummy/public/favicon.ico → dummy3.2/log/.gitkeep} +0 -0
  55. data/spec/{dummy → dummy3.2}/public/404.html +0 -0
  56. data/spec/{dummy → dummy3.2}/public/422.html +0 -0
  57. data/spec/{dummy → dummy3.2}/public/500.html +0 -0
  58. data/spec/dummy3.2/public/favicon.ico +0 -0
  59. data/spec/{dummy → dummy3.2}/script/rails +0 -0
  60. data/spec/dummy4.0/README.rdoc +28 -0
  61. data/spec/dummy4.0/Rakefile +6 -0
  62. data/spec/dummy4.0/app/assets/images/.keep +0 -0
  63. data/spec/dummy4.0/app/assets/javascripts/application.js +13 -0
  64. data/spec/dummy4.0/app/assets/stylesheets/application.css +13 -0
  65. data/spec/dummy4.0/app/controllers/application_controller.rb +5 -0
  66. data/spec/dummy4.0/app/controllers/concerns/.keep +0 -0
  67. data/spec/dummy4.0/app/controllers/pages_controller.rb +4 -0
  68. data/spec/dummy4.0/app/helpers/application_helper.rb +2 -0
  69. data/spec/dummy4.0/app/mailers/.keep +0 -0
  70. data/spec/dummy4.0/app/models/.keep +0 -0
  71. data/spec/dummy4.0/app/models/concerns/.keep +0 -0
  72. data/spec/dummy4.0/app/views/layouts/application.html.erb +14 -0
  73. data/spec/dummy4.0/app/views/pages/index.html.erb +0 -0
  74. data/spec/dummy4.0/app/views/pages/with_html.html.erb +0 -0
  75. data/spec/dummy4.0/app/views/pages/with_html_js.html.erb +0 -0
  76. data/spec/dummy4.0/app/views/pages/with_html_js.js.erb +0 -0
  77. data/spec/dummy4.0/app/views/pages/with_js.js.erb +0 -0
  78. data/spec/dummy4.0/app/views/pages/with_json.json.erb +0 -0
  79. data/spec/dummy4.0/app/views/pages/with_xml.xml.erb +0 -0
  80. data/spec/dummy4.0/bin/bundle +3 -0
  81. data/spec/dummy4.0/bin/rails +4 -0
  82. data/spec/dummy4.0/bin/rake +4 -0
  83. data/spec/dummy4.0/config/application.rb +28 -0
  84. data/spec/dummy4.0/config/boot.rb +5 -0
  85. data/spec/dummy4.0/config/database.yml +25 -0
  86. data/spec/dummy4.0/config/environment.rb +5 -0
  87. data/spec/dummy4.0/config/environments/development.rb +29 -0
  88. data/spec/dummy4.0/config/environments/production.rb +80 -0
  89. data/spec/dummy4.0/config/environments/test.rb +36 -0
  90. data/spec/dummy4.0/config/initializers/backtrace_silencers.rb +7 -0
  91. data/spec/dummy4.0/config/initializers/filter_parameter_logging.rb +4 -0
  92. data/spec/dummy4.0/config/initializers/inflections.rb +16 -0
  93. data/spec/dummy4.0/config/initializers/mime_types.rb +5 -0
  94. data/spec/dummy4.0/config/initializers/secret_token.rb +12 -0
  95. data/spec/dummy4.0/config/initializers/session_store.rb +3 -0
  96. data/spec/dummy4.0/config/initializers/wrap_parameters.rb +14 -0
  97. data/spec/dummy4.0/config/locales/en.yml +23 -0
  98. data/spec/dummy4.0/config/routes.rb +4 -0
  99. data/spec/dummy4.0/config.ru +4 -0
  100. data/spec/dummy4.0/db/test.sqlite3 +0 -0
  101. data/spec/dummy4.0/lib/assets/.keep +0 -0
  102. data/spec/dummy4.0/log/.keep +0 -0
  103. data/spec/dummy4.0/public/404.html +58 -0
  104. data/spec/dummy4.0/public/422.html +58 -0
  105. data/spec/dummy4.0/public/500.html +57 -0
  106. data/spec/dummy4.0/public/favicon.ico +0 -0
  107. data/spec/exception_spec.rb +36 -0
  108. data/spec/hash_options_spec.rb +105 -0
  109. data/spec/rails_behaviour_spec.rb +35 -0
  110. data/spec/skip_filter_spec.rb +99 -0
  111. data/spec/spec_helper.rb +3 -1
  112. data/spec/wildcard_spec.rb +41 -0
  113. data/spec/without_options_spec.rb +73 -0
  114. metadata +216 -88
  115. data/spec/base_spec.rb +0 -429
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9
+ end
10
+
11
+ # To enable root element in JSON for ActiveRecord objects.
12
+ # ActiveSupport.on_load(:active_record) do
13
+ # self.include_root_in_json = true
14
+ # end
@@ -0,0 +1,23 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+ hello: "Hello world"
@@ -0,0 +1,4 @@
1
+ Dummy::Application.routes.draw do
2
+ get "pages/index"
3
+ get "pages/new"
4
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
File without changes
File without changes
File without changes
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagesController, :type => :controller do
4
+
5
+ context "force_format_filter is used with a custom exception" do
6
+
7
+ controller do
8
+ send "force_format_filter", :for => [:js], :exception => lambda { |o| raise(ActiveRecord::RecordNotFound, o) }
9
+
10
+ def index
11
+ render "with_js"
12
+ end
13
+ end
14
+
15
+ it "should respond with RecordNotFound for html" do
16
+ expect { get "index", :format => :html }.to raise_error(ActiveRecord::RecordNotFound)
17
+ end
18
+
19
+ end
20
+
21
+ context "force_format_filter is used with a custom exception but without raising an exception" do
22
+
23
+ controller do
24
+ send "force_format_filter", :for => [:js], :exception => lambda { |o| Rails.logger.info(o) }
25
+
26
+ def index
27
+ render "with_js"
28
+ end
29
+ end
30
+
31
+ it "should respond with MissingTemplate for html" do
32
+ expect { get "index", :format => :html }.to raise_error(ActionView::MissingTemplate)
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagesController, :type => :controller do
4
+
5
+ context "force_format_filter is used with format specified more than once" do
6
+
7
+ controller do
8
+ send "force_format_filter", :for => {:index => [:js], :new => :json}
9
+
10
+ def index
11
+ render "with_js"
12
+ end
13
+
14
+ def new
15
+ render "with_json"
16
+ end
17
+ end
18
+
19
+ it "should respond with 200 for js" do
20
+ get "index", :format => :js
21
+ response.code.should eq("200")
22
+ end
23
+
24
+ it "should respond with 200 for json" do
25
+ get "new", :format => :json
26
+ response.code.should eq("200")
27
+ end
28
+
29
+ it "should respond with RoutingError for html" do
30
+ expect { get "index", :format => :html }.to raise_error(UnknownFormat)
31
+ end
32
+
33
+ it "should respond with RoutingError for html" do
34
+ expect { get "new", :format => :html }.to raise_error(UnknownFormat)
35
+ end
36
+
37
+ end
38
+
39
+ context "force_format_filter is used with format specified more than once but used default" do
40
+
41
+ controller do
42
+ send "force_format_filter", :for => {:index => :js, :default => [:json]}
43
+
44
+ def index
45
+ render "with_js"
46
+ end
47
+
48
+ def new
49
+ render "with_json"
50
+ end
51
+ end
52
+
53
+ it "should respond with 200 for js" do
54
+ get "index", :format => :js
55
+ response.code.should eq("200")
56
+ end
57
+
58
+ it "should respond with 200 for json" do
59
+ get "new", :format => :json
60
+ response.code.should eq("200")
61
+ end
62
+
63
+ it "should respond with RoutingError for html" do
64
+ expect { get "index", :format => :html }.to raise_error(UnknownFormat)
65
+ end
66
+
67
+ it "should respond with RoutingError for html" do
68
+ expect { get "new", :format => :html }.to raise_error(UnknownFormat)
69
+ end
70
+
71
+ end
72
+
73
+
74
+ context "force_format_filter is used with unsupported format" do
75
+
76
+ controller do
77
+ send "force_format_filter", :for => {:index => :what}
78
+
79
+ def index
80
+ render "with_js"
81
+ end
82
+ end
83
+
84
+ it "should respond with UnsupportedFormat for html" do
85
+ expect { get "index", :format => :html }.to raise_error(UnsupportedFormat)
86
+ end
87
+
88
+ end
89
+
90
+ context "force_format_filter is used with unsupported format" do
91
+
92
+ controller do
93
+ send "force_format_filter", :for => {:index => :what}
94
+
95
+ def index
96
+ render "with_js"
97
+ end
98
+ end
99
+
100
+ it "should respond with UnsupportedFormat for html" do
101
+ expect { get "index", :format => :html }.to raise_error(UnsupportedFormat)
102
+ end
103
+
104
+ end
105
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagesController, :type => :controller do
4
+
5
+ context "force_format_filter is not used (rails defaults)" do
6
+
7
+ controller do
8
+ def index
9
+ end
10
+ end
11
+
12
+ it "should respond with 200 for html" do
13
+ get "index"
14
+ response.code.should eq("200")
15
+ end
16
+
17
+ it "should respond with 200 for html" do
18
+ get "index", :format => :html
19
+ response.code.should eq("200")
20
+ end
21
+
22
+ it "should respond with MissingTemplate for js" do
23
+ expect { get "index", :format => :js }.to raise_error(ActionView::MissingTemplate)
24
+ end
25
+
26
+ it "should respond with MissingTemplate for xml" do
27
+ expect { get "index", :format => :xml }.to raise_error(ActionView::MissingTemplate)
28
+ end
29
+
30
+ it "should respond with MissingTemplate for json" do
31
+ expect { get "index", :format => :json }.to raise_error(ActionView::MissingTemplate)
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagesController, :type => :controller do
4
+
5
+ context "force_format_filter is not used but skip_format_filter specified for all actions" do
6
+
7
+ controller do
8
+ send "skip_force_format_filter"
9
+
10
+ def index
11
+ end
12
+ end
13
+
14
+ it "should respond with 200 for html" do
15
+ get "index"
16
+ response.code.should eq("200")
17
+ end
18
+
19
+ it "should respond with 200 for html" do
20
+ get "index", :format => :html
21
+ response.code.should eq("200")
22
+ end
23
+
24
+ it "should respond with MissingTemplate for js" do
25
+ expect { get "index", :format => :js }.to raise_error(ActionView::MissingTemplate)
26
+ end
27
+
28
+ it "should respond with MissingTemplate for xml" do
29
+ expect { get "index", :format => :xml }.to raise_error(ActionView::MissingTemplate)
30
+ end
31
+
32
+ it "should respond with MissingTemplate for json" do
33
+ expect { get "index", :format => :json }.to raise_error(ActionView::MissingTemplate)
34
+ end
35
+
36
+ end
37
+
38
+ context "force_format_filter is used with no format specified for :index actions" do
39
+
40
+ controller do
41
+ send "force_format_filter", :only => :index
42
+ send "skip_force_format_filter", :only => :skipped
43
+
44
+ def new
45
+ render "with_html"
46
+ end
47
+
48
+ def index
49
+ render "with_html"
50
+ end
51
+ end
52
+
53
+ it "should respond with 200 for html" do
54
+ get "index"
55
+ response.code.should eq("200")
56
+ end
57
+
58
+ it "should respond with 200 for html" do
59
+ get "index", :format => :html
60
+ response.code.should eq("200")
61
+ end
62
+
63
+ it "should respond with RoutingError for js" do
64
+ expect { get "index", :format => :js }.to raise_error(UnknownFormat)
65
+ end
66
+
67
+ it "should respond with RoutingError for xml" do
68
+ expect { get "index", :format => :xml }.to raise_error(UnknownFormat)
69
+ end
70
+
71
+ it "should respond with RoutingError for json" do
72
+ expect { get "index", :format => :json }.to raise_error(UnknownFormat)
73
+ end
74
+
75
+
76
+ it "should respond with 200 for html" do
77
+ get "new"
78
+ response.code.should eq("200")
79
+ end
80
+
81
+ it "should respond with 200 for html" do
82
+ get "new", :format => :html
83
+ response.code.should eq("200")
84
+ end
85
+
86
+ it "should respond with MissingTemplate for js" do
87
+ expect { get "new", :format => :js }.to raise_error(ActionView::MissingTemplate)
88
+ end
89
+
90
+ it "should respond with MissingTemplate for xml" do
91
+ expect { get "new", :format => :xml }.to raise_error(ActionView::MissingTemplate)
92
+ end
93
+
94
+ it "should respond with MissingTemplate for json" do
95
+ expect { get "new", :format => :json }.to raise_error(ActionView::MissingTemplate)
96
+ end
97
+
98
+ end
99
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # Configure Rails Environment
2
2
  ENV["RAILS_ENV"] = "test"
3
3
 
4
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
+ rails_version = ENV['RAILS_VERSION'] || "3.2"
5
+
6
+ require File.expand_path("../dummy#{rails_version}/config/environment.rb", __FILE__)
5
7
  require 'rspec/rails'
6
8
  require 'rspec/autorun'
7
9
  require 'force_format'
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagesController, :type => :controller do
4
+
5
+ context "force_format_filter is used with a wildcard format and rewrite set" do
6
+
7
+ controller do
8
+ send "force_format_filter", :for => :html, :skip_wildcard => false
9
+
10
+ def index
11
+ render "with_html"
12
+ end
13
+ end
14
+
15
+ it "should respond with 200 for html" do
16
+ request.env["HTTP_ACCEPT"] = '*/*'
17
+ get "index"
18
+ end
19
+
20
+ end
21
+
22
+ context "force_format_filter is used with a wildcard format and rewrite set to false" do
23
+
24
+ controller do
25
+ send "force_format_filter", :for => :html, :skip_wildcard => true
26
+
27
+ def index
28
+ render "with_html"
29
+ end
30
+ end
31
+
32
+ it "should respond with RoutingError for html" do
33
+ expect do
34
+ request.env["HTTP_ACCEPT"] = '*/*'
35
+ get "index"
36
+ end.to raise_error(UnknownFormat)
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagesController, :type => :controller do
4
+
5
+ context "force_format_filter is used with no format specified for all actions" do
6
+
7
+ controller do
8
+ send "force_format_filter"
9
+
10
+ def index
11
+ end
12
+ end
13
+
14
+ it "should respond with 200 for html" do
15
+ get "index"
16
+ response.code.should eq("200")
17
+ end
18
+
19
+ it "should respond with 200 for html" do
20
+ get "index", :format => :html
21
+ response.code.should eq("200")
22
+ end
23
+
24
+ it "should respond with RoutingError for js" do
25
+ expect { get "index", :format => :js }.to raise_error(UnknownFormat)
26
+ end
27
+
28
+ it "should respond with RoutingError for xml" do
29
+ expect { get "index", :format => :xml }.to raise_error(UnknownFormat)
30
+ end
31
+
32
+ it "should respond with RoutingError for json" do
33
+ expect { get "index", :format => :json }.to raise_error(UnknownFormat)
34
+ end
35
+
36
+ end
37
+
38
+
39
+ context "force_format_filter is used with skip_format_filter specified for all actions" do
40
+
41
+ controller do
42
+ send "force_format_filter"
43
+ send "skip_force_format_filter"
44
+
45
+ def index
46
+ end
47
+ end
48
+
49
+ it "should respond with 200 for html" do
50
+ get "index"
51
+ response.code.should eq("200")
52
+ end
53
+
54
+ it "should respond with 200 for html" do
55
+ get "index", :format => :html
56
+ response.code.should eq("200")
57
+ end
58
+
59
+ it "should respond with MissingTemplate for js" do
60
+ expect { get "index", :format => :js }.to raise_error(ActionView::MissingTemplate)
61
+ end
62
+
63
+ it "should respond with MissingTemplate for xml" do
64
+ expect { get "index", :format => :xml }.to raise_error(ActionView::MissingTemplate)
65
+ end
66
+
67
+ it "should respond with MissingTemplate for json" do
68
+ expect { get "index", :format => :json }.to raise_error(ActionView::MissingTemplate)
69
+ end
70
+
71
+ end
72
+
73
+ end