rapidoc 0.0.4
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.
- data/.gitignore +21 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +152 -0
- data/Rakefile +1 -0
- data/lib/rapidoc.rb +62 -0
- data/lib/rapidoc/action_doc.rb +86 -0
- data/lib/rapidoc/config.rb +127 -0
- data/lib/rapidoc/config/rapidoc.yml +4 -0
- data/lib/rapidoc/controller_extractor.rb +54 -0
- data/lib/rapidoc/http_response.rb +61 -0
- data/lib/rapidoc/param_errors.rb +43 -0
- data/lib/rapidoc/resource_doc.rb +66 -0
- data/lib/rapidoc/resources_extractor.rb +42 -0
- data/lib/rapidoc/routes_doc.rb +96 -0
- data/lib/rapidoc/templates/action.html.hbs +170 -0
- data/lib/rapidoc/templates/assets/css/bootstrap-responsive.min.css +9 -0
- data/lib/rapidoc/templates/assets/css/bootstrap.min.css +9 -0
- data/lib/rapidoc/templates/assets/css/rapidoc.css +43 -0
- data/lib/rapidoc/templates/assets/img/glyphicons-halflings.png +0 -0
- data/lib/rapidoc/templates/assets/js/bootstrap.min.js +6 -0
- data/lib/rapidoc/templates/assets/js/jquery-1.9.0.min.js +4 -0
- data/lib/rapidoc/templates/assets/js/json2.js +486 -0
- data/lib/rapidoc/templates/index.html.hbs +85 -0
- data/lib/rapidoc/templates_generator.rb +65 -0
- data/lib/rapidoc/version.rb +3 -0
- data/lib/rapidoc/yaml_parser.rb +49 -0
- data/lib/tasks/railtie.rb +7 -0
- data/lib/tasks/rapidoc.rake +18 -0
- data/rapidoc.gemspec +26 -0
- data/spec/dummy/.gitignore +15 -0
- data/spec/dummy/Gemfile +42 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/images/rails.png +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/users_controller.rb +114 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +62 -0
- data/spec/dummy/config/boot.rb +6 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +9 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/lib/tasks/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/index.html +241 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/salida/users_create_response.json +12 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/test/fixtures/.gitkeep +0 -0
- data/spec/dummy/test/functional/.gitkeep +0 -0
- data/spec/dummy/test/integration/.gitkeep +0 -0
- data/spec/dummy/test/performance/browsing_test.rb +12 -0
- data/spec/dummy/test/test_helper.rb +13 -0
- data/spec/dummy/test/unit/.gitkeep +0 -0
- data/spec/dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/features/action_spec.rb +212 -0
- data/spec/features/index_spec.rb +64 -0
- data/spec/lib/action_doc_spec.rb +202 -0
- data/spec/lib/config_spec.rb +186 -0
- data/spec/lib/controller_extractor_spec.rb +77 -0
- data/spec/lib/http_response_spec.rb +63 -0
- data/spec/lib/param_errors_spec.rb +69 -0
- data/spec/lib/rake_spec.rb +25 -0
- data/spec/lib/rapidoc_spec.rb +39 -0
- data/spec/lib/resource_doc_spec.rb +131 -0
- data/spec/lib/resources_extractor_spec.rb +105 -0
- data/spec/lib/routes_doc_spec.rb +150 -0
- data/spec/lib/templates_generator_spec.rb +90 -0
- data/spec/lib/yard_parser_spec.rb +55 -0
- data/spec/spec_helper.rb +10 -0
- metadata +307 -0
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'rails/performance_test_help'
|
|
3
|
+
|
|
4
|
+
class BrowsingTest < ActionDispatch::PerformanceTest
|
|
5
|
+
# Refer to the documentation for all available options
|
|
6
|
+
# self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
|
|
7
|
+
# :output => 'tmp/performance', :formats => [:flat] }
|
|
8
|
+
|
|
9
|
+
def test_homepage
|
|
10
|
+
get '/'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
|
2
|
+
require File.expand_path('../../config/environment', __FILE__)
|
|
3
|
+
require 'rails/test_help'
|
|
4
|
+
|
|
5
|
+
class ActiveSupport::TestCase
|
|
6
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
|
7
|
+
#
|
|
8
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
|
9
|
+
# -- they do not yet inherit this setting
|
|
10
|
+
fixtures :all
|
|
11
|
+
|
|
12
|
+
# Add more helper methods to be used by all tests here...
|
|
13
|
+
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
require 'bundler/setup'
|
|
2
|
+
require 'rack/file'
|
|
3
|
+
require 'capybara/rspec'
|
|
4
|
+
require 'spec_helper'
|
|
5
|
+
require 'rspec/rails'
|
|
6
|
+
|
|
7
|
+
Capybara.app = Rack::File.new ::Rails.root.to_s
|
|
8
|
+
|
|
9
|
+
include Rapidoc
|
|
10
|
+
|
|
11
|
+
describe "Action page" do
|
|
12
|
+
|
|
13
|
+
before :all do
|
|
14
|
+
reset_structure
|
|
15
|
+
|
|
16
|
+
@json_info = { "user" => { "name" => "Check", "apellido" => "Me" } }
|
|
17
|
+
request_file = examples_dir "users_create_request.json"
|
|
18
|
+
response_file = examples_dir "users_create_response.json"
|
|
19
|
+
|
|
20
|
+
File.open( request_file, 'w') { |file| file.write @json_info.to_json }
|
|
21
|
+
File.open( response_file, 'w') { |file| file.write @json_info.to_json }
|
|
22
|
+
|
|
23
|
+
load_config
|
|
24
|
+
resources_doc = get_resources
|
|
25
|
+
generate_actions_templates( resources_doc )
|
|
26
|
+
|
|
27
|
+
@user_resource = resources_doc.select{ |r| r.name == 'users' }.first
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
after :all do
|
|
31
|
+
remove_doc
|
|
32
|
+
remove_examples
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context "when visit users_index.html page" do
|
|
36
|
+
before do
|
|
37
|
+
visit '/rapidoc/actions/users_index.html'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context "when check action page" do
|
|
41
|
+
it "contains title with text 'Project'" do
|
|
42
|
+
config = YAML.load( File.read( config_file_path ) )
|
|
43
|
+
page.should have_link( config["project_name"], '#' )
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "contains an H1 with text 'user'" do
|
|
47
|
+
page.should have_css 'h1', :text => @user_resource.name.to_s
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context "when check tab 'Home'" do
|
|
52
|
+
before :all do
|
|
53
|
+
@action_info = @user_resource.actions_doc.first
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "contains a description of the resource" do
|
|
57
|
+
page.should have_text(@action_info.description)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "contains action name" do
|
|
61
|
+
page.should have_css("td", @action_info.action)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "contains action method" do
|
|
65
|
+
page.should have_css("td", @action_info.action_method)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "contains action response formats" do
|
|
69
|
+
page.should have_css("td", @action_info.response_formats)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "contains icon that show if action requires authentication" do
|
|
73
|
+
if @action_info.authentication == true
|
|
74
|
+
page.should have_css("i.icon-ok")
|
|
75
|
+
else
|
|
76
|
+
page.should have_css("i.icon-remove")
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "contains the resource URL" do
|
|
81
|
+
page.should have_text(@action_info.urls.first)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "contains the correct states" do
|
|
85
|
+
@action_info.http_responses.each do |http_response|
|
|
86
|
+
page.should have_css("td", http_response.description)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
context "when check tab 'Params'" do
|
|
92
|
+
before :all do
|
|
93
|
+
@params_info = @user_resource.actions_doc.first.params
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "have table with one row for each parameter" do
|
|
97
|
+
# +1 becouse rapidoc add empty row at the end
|
|
98
|
+
page.should have_css( "table#table-params tr", :count => @params_info.size + 1 )
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "have a row with parameter name" do
|
|
102
|
+
@params_info.each do |param|
|
|
103
|
+
page.should have_css( "table#table-params td", :text => /#{param["name"]}.*/ )
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "have a row with parameter type" do
|
|
108
|
+
@params_info.each do |param|
|
|
109
|
+
if param.keys.include? "type"
|
|
110
|
+
page.should have_css( "table#table-params td", :text => /.*#{param["type"]}/ )
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "have a row with parameter description" do
|
|
116
|
+
@params_info.each do |param|
|
|
117
|
+
page.should have_css( "table#table-params td", :text => param["description"] )
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "have a row with parameter type" do
|
|
122
|
+
@params_info.each do |param|
|
|
123
|
+
page.should have_css( "table#table-params td", :text => param["type"] )
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it "don't have tab 'Errors'" do
|
|
129
|
+
page.should_not have_css( "div#errors" )
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it "don't have tab 'Request'" do
|
|
133
|
+
page.should_not have_css( "div#request" )
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "don't have tab 'Response'" do
|
|
137
|
+
page.should_not have_text( "div#response" )
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
context "when visit users_create.html page" do
|
|
142
|
+
before do
|
|
143
|
+
visit '/rapidoc/actions/users_create.html'
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
context "when check tab 'Params'" do
|
|
147
|
+
before do
|
|
148
|
+
@create_params_info =
|
|
149
|
+
@user_resource.actions_doc.select{ |ad| ad.action == 'create' }.first.params
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it "have a row with parameter type or inclusion" do
|
|
153
|
+
@create_params_info.each do |param|
|
|
154
|
+
if param["inclusion"]
|
|
155
|
+
page.should have_css( "table#table-params td", :text => param["inclusion"] )
|
|
156
|
+
else
|
|
157
|
+
page.should have_css( "table#table-params td", :text => param["type"] )
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
context "when check tab 'Errors'" do
|
|
164
|
+
before :all do
|
|
165
|
+
action_doc = @user_resource.actions_doc.select{ |ad| ad.action == "create" }.first
|
|
166
|
+
@errors = action_doc.errors
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it "have table with one row for each error" do
|
|
170
|
+
header = 1
|
|
171
|
+
page.should have_css( "table#table-errors tr", :count => @errors.size + header )
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it "have a col with error object" do
|
|
175
|
+
@errors.each do |error|
|
|
176
|
+
page.should have_css( "table#table-errors td", :text => /#{error["object"]}.*/ )
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it "have a col with error message" do
|
|
181
|
+
@errors.each do |error|
|
|
182
|
+
page.should have_css( "table#table-errors td", :text => /#{error["message"]}.*/ )
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it "have a col with error description" do
|
|
187
|
+
@errors.each do |error|
|
|
188
|
+
page.should have_css( "table#table-errors td", :text => /#{error["description"]}.*/ )
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it "have a row with error message" do
|
|
193
|
+
@errors.each do |error|
|
|
194
|
+
page.should have_css( "table#table-errors tr",
|
|
195
|
+
:text => /#{error["object"]}.#{error["message"]}.*#{error["description"]}/ )
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
context "when check tab 'Request'" do
|
|
201
|
+
it "should contain the correct request" do
|
|
202
|
+
page.should have_text( @user_resource.actions_doc.first.example_req )
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
context "when check tab 'Response'" do
|
|
207
|
+
it "should contain the correct response" do
|
|
208
|
+
page.should have_text( @user_resource.actions_doc.first.example_res )
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require 'bundler/setup'
|
|
2
|
+
require 'rack/file'
|
|
3
|
+
require 'capybara/rspec'
|
|
4
|
+
require 'spec_helper'
|
|
5
|
+
|
|
6
|
+
Capybara.app = Rack::File.new ::Rails.root.to_s
|
|
7
|
+
|
|
8
|
+
include Rapidoc
|
|
9
|
+
|
|
10
|
+
describe "Index page" do
|
|
11
|
+
|
|
12
|
+
before :all do
|
|
13
|
+
reset_structure
|
|
14
|
+
load_config
|
|
15
|
+
@resources = get_resources
|
|
16
|
+
generate_doc
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
before do
|
|
20
|
+
visit '/rapidoc/index.html'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
after :all do
|
|
24
|
+
#remove_doc
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "when check global page" do
|
|
28
|
+
it "contains an H1 with text 'Resources'" do
|
|
29
|
+
page.should have_css 'h1', :text => 'Resources'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "contains Title with text 'Project Name'" do
|
|
33
|
+
page.should have_link('Project Name', '#')
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context "when check resources" do
|
|
38
|
+
it "contains the correct number of resources" do
|
|
39
|
+
page.find(".accordion").should have_content "albums"
|
|
40
|
+
page.find(".accordion").should have_content "images"
|
|
41
|
+
page.find(".accordion").should have_content "users"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "contains the correct methods" do
|
|
45
|
+
@resources.each do |resource|
|
|
46
|
+
resource.actions_doc.each do |action|
|
|
47
|
+
action.urls.each do |url|
|
|
48
|
+
if action.has_controller_info
|
|
49
|
+
page.should have_link( url, href: "actions/" + action.file + ".html" )
|
|
50
|
+
else
|
|
51
|
+
page.should have_text( url )
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "contains the correct description" do
|
|
59
|
+
@resources.each do |resource|
|
|
60
|
+
page.should have_text(resource.description)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
require 'spec_helper.rb'
|
|
2
|
+
|
|
3
|
+
include Rapidoc
|
|
4
|
+
|
|
5
|
+
describe ActionDoc do
|
|
6
|
+
|
|
7
|
+
before :all do
|
|
8
|
+
@json_info = { "user" => { "name" => "Check", "apellido" => "Me" } }
|
|
9
|
+
response_file = examples_dir "users_create_response.json"
|
|
10
|
+
answer_file = examples_dir "users_create_request.json"
|
|
11
|
+
|
|
12
|
+
reset_structure
|
|
13
|
+
File.open( response_file, 'w') { |file| file.write @json_info.to_json }
|
|
14
|
+
File.open( answer_file, 'w') { |file| file.write @json_info.to_json }
|
|
15
|
+
|
|
16
|
+
@info = {
|
|
17
|
+
:resource=>"users",
|
|
18
|
+
:action=>"create",
|
|
19
|
+
:method=>"POST",
|
|
20
|
+
:urls=>["/users(.:format)"]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
extractor = ControllerExtractor.new "users_controller.rb"
|
|
24
|
+
@controller_info = extractor.get_action_info( 'create' )
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
after :all do
|
|
28
|
+
remove_examples
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context "when initialize ActionDoc" do
|
|
32
|
+
before :all do
|
|
33
|
+
@action_doc = ActionDoc.new( @info, @controller_info, examples_dir )
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "set correct action info" do
|
|
37
|
+
@action_doc.action.should == @info[:action]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "set correct resource" do
|
|
41
|
+
@action_doc.resource.should == @info[:resource]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "set correct urls" do
|
|
45
|
+
@action_doc.urls.should == @info[:urls]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "set correct action method" do
|
|
49
|
+
@action_doc.action_method.should == @info[:method]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "set correct description" do
|
|
53
|
+
@action_doc.description.should == @controller_info["description"]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "set correct http responses" do
|
|
57
|
+
http_responses = @action_doc.send( :get_http_responses,
|
|
58
|
+
@controller_info["http_responses"] )
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "set correct requires authentication" do
|
|
62
|
+
@action_doc.authentication.should == false
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "set correct file" do
|
|
66
|
+
@action_doc.file.should == @info[:resource].to_s + "_" + @info[:action].to_s
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "set correct example_req" do
|
|
70
|
+
@action_doc.example_res.should == JSON.pretty_generate( @json_info )
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "set correct example_res" do
|
|
74
|
+
@action_doc.example_req.should == JSON.pretty_generate( @json_info )
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
context "when executing get_http_responses method" do
|
|
78
|
+
before do
|
|
79
|
+
@codes = [ 200, 401 ]
|
|
80
|
+
@http_responses = @action_doc.send( :get_http_responses, @codes )
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "return new HttpResponse Array" do
|
|
84
|
+
@http_responses.each do |r|
|
|
85
|
+
r.class.should == HttpResponse
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "each HttpResponse element should include correct code" do
|
|
90
|
+
@http_responses.each_index do |i|
|
|
91
|
+
@http_responses[i].code.should == @codes[i]
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "each HttpResponse element should include description" do
|
|
96
|
+
@http_responses.each{ |http_r| http_r.methods.should be_include( :description ) }
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "each HttpResponse element should include label" do
|
|
100
|
+
@http_responses.each{ |http_r| http_r.methods.should be_include( :label ) }
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
context "when checking errors" do
|
|
105
|
+
context "when action has custom errors" do
|
|
106
|
+
before :all do
|
|
107
|
+
@errors = @action_doc.errors
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "return all errors" do
|
|
111
|
+
@errors.size.should == 1
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "return password errors" do
|
|
115
|
+
params_errors = @errors.select{ |error| error["object"] == 'password' }
|
|
116
|
+
messages = params_errors.map{ |m| m["message"] }
|
|
117
|
+
messages.should be_include( 'too_short' )
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
context "when call get_authentication function" do
|
|
123
|
+
context "when pass true/false" do
|
|
124
|
+
it "return correctly value" do
|
|
125
|
+
@action_doc.send( :get_authentication, false ).should == false
|
|
126
|
+
@action_doc.send( :get_authentication, true ).should == true
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
context "when pass nil" do
|
|
130
|
+
it "return correctly default value (true)" do
|
|
131
|
+
@action_doc.send( :get_authentication, nil ).should == true
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
context "when default response formats are actived" do
|
|
138
|
+
before :all do
|
|
139
|
+
File.open("#{config_dir}/rapidoc.yml", 'w') do |file|
|
|
140
|
+
file.write "response_formats: xml"
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
load_config
|
|
144
|
+
@action_doc = ActionDoc.new( @info, @controller_info, examples_dir )
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it "returns default response formats" do
|
|
148
|
+
@action_doc.response_formats.should == 'xml'
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
context "when default errors are actived" do
|
|
153
|
+
context "when use default messages and descriptions" do
|
|
154
|
+
before :all do
|
|
155
|
+
File.open("#{config_dir}/rapidoc.yml", 'w') do |file|
|
|
156
|
+
file.write "default_errors: true"
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
load_config
|
|
160
|
+
action_doc = ActionDoc.new( @info, @controller_info, examples_dir )
|
|
161
|
+
@errors = action_doc.errors
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it "return all errors" do
|
|
165
|
+
@errors.size.should == 6
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it "returns correct messages" do
|
|
169
|
+
messages = @errors.map{ |error| error["message"] }
|
|
170
|
+
messages.should be_include( 'blank' )
|
|
171
|
+
messages.should be_include( 'too_short' )
|
|
172
|
+
messages.should be_include( 'inclusion' )
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
context "when use config messages and descriptions" do
|
|
177
|
+
before :all do
|
|
178
|
+
File.open( config_file_path, 'w') do |file|
|
|
179
|
+
file.write "default_errors: true\n"
|
|
180
|
+
file.write "errors:\n"
|
|
181
|
+
file.write " required:\n message: \"m1\"\n description: \"d1\"\n"
|
|
182
|
+
file.write " inclusion:\n message: \"m2\"\n description: \"d2\"\n"
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
load_config
|
|
186
|
+
action_doc = ActionDoc.new( @info, @controller_info, examples_dir )
|
|
187
|
+
@errors = action_doc.errors
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it "return all errors" do
|
|
191
|
+
@errors.size.should == 6
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
it "returns correct messages" do
|
|
195
|
+
messages = @errors.map{ |error| error["message"] }
|
|
196
|
+
messages.should be_include( 'm1' )
|
|
197
|
+
messages.should be_include( 'too_short' )
|
|
198
|
+
messages.should be_include( 'm2' )
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|