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
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
require 'spec_helper.rb'
|
|
2
|
+
|
|
3
|
+
include Rapidoc
|
|
4
|
+
|
|
5
|
+
describe ResourceDoc do
|
|
6
|
+
before :all do
|
|
7
|
+
@extractor = ControllerExtractor.new "users_controller.rb"
|
|
8
|
+
@routes_actions_info = get_routes_doc.get_actions_route_info( :users )
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
context "when create new valid instance only with resource name" do
|
|
12
|
+
before do
|
|
13
|
+
@resource_name = "users"
|
|
14
|
+
@rdoc = ResourceDoc.new @resource_name, nil
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "saves it correctly" do
|
|
18
|
+
@rdoc.name.should == @resource_name
|
|
19
|
+
@rdoc.controller_file.should == @resource_name + '_controller.rb'
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context "when call simple name" do
|
|
24
|
+
before do
|
|
25
|
+
@resource_name = "One/Two"
|
|
26
|
+
@rdoc = ResourceDoc.new @resource_name, nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "returns name without '/'" do
|
|
30
|
+
@rdoc.simple_name.should == "OneTwo"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "when call get_controller_extractor function" do
|
|
35
|
+
before do
|
|
36
|
+
ResourceDoc.any_instance.stub( :generate_info ).and_return( true )
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
context "when exists controller file" do
|
|
40
|
+
before do
|
|
41
|
+
@rdoc = ResourceDoc.new "users", nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "returns new ControllerExtractor" do
|
|
45
|
+
@rdoc.send( :get_controller_extractor ).class.should == ControllerExtractor
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context "when exists controller file" do
|
|
50
|
+
before do
|
|
51
|
+
@rdoc = ResourceDoc.new "notexists", nil
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "returns new ControllerExtractor" do
|
|
55
|
+
@rdoc.send( :get_controller_extractor ).should == nil
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
context "when call get_actions_doc function" do
|
|
61
|
+
before do
|
|
62
|
+
ResourceDoc.any_instance.stub( :generate_info ).and_return( true )
|
|
63
|
+
@rdoc = ResourceDoc.new "users", nil
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context "when don't pass extractor" do
|
|
67
|
+
before do
|
|
68
|
+
@actions_doc = @rdoc.send( :get_actions_doc, @routes_actions_info, nil )
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "returns ActionDoc array" do
|
|
72
|
+
@actions_doc.class.should == Array
|
|
73
|
+
@actions_doc.each{ |ad| ad.class.should == ActionDoc }
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "don't returns description" do
|
|
77
|
+
@actions_doc.each{ |ad| ad.description.should == nil }
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "ActionDoc array has correct info" do
|
|
81
|
+
actions = @actions_doc.map{ |ad| ad.action }
|
|
82
|
+
methods = @actions_doc.map{ |ad| ad.action_method }
|
|
83
|
+
|
|
84
|
+
# Example of routes_actions_info: { index => [{},{}], show => [{}] }
|
|
85
|
+
@routes_actions_info.each do |action_info|
|
|
86
|
+
actions.should be_include( action_info[:action] )
|
|
87
|
+
methods.should be_include( action_info[:method] )
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
context "when pass resource action info (routes) and extractor" do
|
|
93
|
+
before do
|
|
94
|
+
@actions_doc = @rdoc.send( :get_actions_doc, @routes_actions_info, @extractor )
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "returns ActionDoc array" do
|
|
98
|
+
@actions_doc.class.should == Array
|
|
99
|
+
@actions_doc.each{ |ad| ad.class.should == ActionDoc }
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "returns info extracted from controller" do
|
|
103
|
+
@actions_doc.each do |action_doc|
|
|
104
|
+
info = @extractor.get_action_info( action_doc.action )
|
|
105
|
+
action_doc.description.should == info['description']
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
context "when create new valid instance" do
|
|
112
|
+
before :all do
|
|
113
|
+
@resource_name = "users"
|
|
114
|
+
@rdoc = ResourceDoc.new @resource_name, @routes_actions_info
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "saves it correctly" do
|
|
118
|
+
@rdoc.name.should == @resource_name
|
|
119
|
+
@rdoc.controller_file.should == @resource_name + '_controller.rb'
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "set correct description" do
|
|
123
|
+
@rdoc.description.should == @extractor.get_resource_info['description']
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "set correct actions_doc" do
|
|
127
|
+
@rdoc.actions_doc.class.should == Array
|
|
128
|
+
@rdoc.actions_doc.each{ |ad| ad.class.should == ActionDoc }
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
include Rapidoc
|
|
4
|
+
|
|
5
|
+
describe Rapidoc::ResourcesExtractor do
|
|
6
|
+
|
|
7
|
+
context "when executing get_routes_doc" do
|
|
8
|
+
before :all do
|
|
9
|
+
@routes_doc = get_routes_doc
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "returns RoutesDoc instance" do
|
|
13
|
+
@routes_doc.class.should == RoutesDoc
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "instance include all resources" do
|
|
17
|
+
resources_names = @routes_doc.get_resources_names
|
|
18
|
+
resources_names.should be_include(:images)
|
|
19
|
+
resources_names.should be_include(:albums)
|
|
20
|
+
resources_names.should be_include(:users)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context "when executing get_routes_doc and config has resources black list" do
|
|
25
|
+
before :all do
|
|
26
|
+
@routes_doc = get_routes_doc
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "returns RoutesDoc instance" do
|
|
30
|
+
@routes_doc.class.should == RoutesDoc
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "instance include all resources" do
|
|
34
|
+
resources_names = @routes_doc.get_resources_names
|
|
35
|
+
resources_names.should be_include(:images)
|
|
36
|
+
resources_names.should be_include(:albums)
|
|
37
|
+
resources_names.should be_include(:users)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
context "when executing get_resources function" do
|
|
43
|
+
before :all do
|
|
44
|
+
@resources = get_resources
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "return correct resorces name" do
|
|
48
|
+
names = @resources.map(&:name)
|
|
49
|
+
names.should be_include( "images" )
|
|
50
|
+
names.should be_include( "users" )
|
|
51
|
+
names.should be_include( "albums" )
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "return correct controller_names" do
|
|
55
|
+
files = @resources.map(&:controller_file)
|
|
56
|
+
files.should be_include( "images_controller.rb" )
|
|
57
|
+
files.should be_include( "users_controller.rb" )
|
|
58
|
+
files.should be_include( "albums_controller.rb" )
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "return correct resource actions" do
|
|
62
|
+
@user_resource = @resources.select{ |r| r.name == "users" }.first
|
|
63
|
+
actions = @user_resource.actions_doc.map{ |r| r.action }
|
|
64
|
+
|
|
65
|
+
actions.should be_include( 'index' )
|
|
66
|
+
actions.should be_include( 'show' )
|
|
67
|
+
actions.should be_include( 'create' )
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "return correct order" do
|
|
71
|
+
names = @resources.map(&:name)
|
|
72
|
+
names.should == [ "albums", "images", "users" ]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
context "when check resource with controller" do
|
|
76
|
+
before do
|
|
77
|
+
@user_resource = @resources.select{ |r| r.name == "users" }.first
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "return correct info about controller actions" do
|
|
81
|
+
actions = @user_resource.actions_doc.map{ |r| r.action }
|
|
82
|
+
actions.should be_include( 'index' )
|
|
83
|
+
actions.should be_include( 'show' )
|
|
84
|
+
actions.should be_include( 'create' )
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
context "when config has resources_black_list" do
|
|
89
|
+
before do
|
|
90
|
+
File.open("#{config_dir}/rapidoc.yml", 'w') do |file|
|
|
91
|
+
file.write "resources_black_list: images, albums"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
load_config
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "returns correct resources names" do
|
|
98
|
+
names = get_resources.map(&:name)
|
|
99
|
+
names.should_not be_include( "images" )
|
|
100
|
+
names.should_not be_include( "albums" )
|
|
101
|
+
names.should be_include( "users" )
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
require 'spec_helper.rb'
|
|
2
|
+
|
|
3
|
+
include Rapidoc
|
|
4
|
+
|
|
5
|
+
describe RoutesDoc do
|
|
6
|
+
before do
|
|
7
|
+
@routes_doc = RoutesDoc.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context "when we call add_resource_route function" do
|
|
11
|
+
before do
|
|
12
|
+
@method = 'GET'
|
|
13
|
+
@url = '/users(.:format)'
|
|
14
|
+
@controller_action = 'users#index'
|
|
15
|
+
@routes_doc.send( :add_resource_route, @method, @url, @controller_action )
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "adds new route to RoutesDoc instance" do
|
|
19
|
+
@routes_doc.instance_variable_get( :@resources_routes ).size.should == 1
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "creates correct route resource" do
|
|
23
|
+
resources = @routes_doc.instance_variable_get( :@resources_routes ).keys
|
|
24
|
+
resources.should be_include( :users )
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "set correct route info" do
|
|
28
|
+
info = @routes_doc.instance_variable_get( :@resources_routes )[:users].first
|
|
29
|
+
|
|
30
|
+
info[:resource].should == 'users'
|
|
31
|
+
info[:action].should == 'index'
|
|
32
|
+
info[:method].should == @method
|
|
33
|
+
info[:url].should == @url
|
|
34
|
+
info[:controller].should == 'users'
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context "when we call get_resource_name function" do
|
|
39
|
+
context "when resource name is at the end of url" do
|
|
40
|
+
context "when is embeded resource" do
|
|
41
|
+
it "returns correct resource name" do
|
|
42
|
+
name = @routes_doc.send( :get_resource_name, '/users/:id/images(.:format)' )
|
|
43
|
+
name.should == 'images'
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context "when not is embeded resource" do
|
|
48
|
+
it "returns correct resource name" do
|
|
49
|
+
name = @routes_doc.send( :get_resource_name, '/users(.:format)' )
|
|
50
|
+
name.should == 'users'
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context "when resource name is followed by id" do
|
|
56
|
+
it "returns correct resource name" do
|
|
57
|
+
name = @routes_doc.send( :get_resource_name, '/users/:id/images/:id(.:format)' )
|
|
58
|
+
name.should == 'images'
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
context "when resource name is followed by action" do
|
|
63
|
+
it "returns correct resource name" do
|
|
64
|
+
name = @routes_doc.send( :get_resource_name, '/users/:id/images/new(.:format)' )
|
|
65
|
+
name.should == 'images'
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
context "when is edit action" do
|
|
70
|
+
it "returns correct resource name" do
|
|
71
|
+
name = @routes_doc.send( :get_resource_name, '/users/:id/edit(.:format)' )
|
|
72
|
+
name.should == 'users'
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
context "when is edit action from embeded resource" do
|
|
77
|
+
it "returns correct resource name" do
|
|
78
|
+
name = @routes_doc.send( :get_resource_name, '/users/password/edit(.:format)' )
|
|
79
|
+
name.should == 'users'
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
context "when is root" do
|
|
84
|
+
it "returns correct resource name" do
|
|
85
|
+
name = @routes_doc.send( :get_resource_name, '/' )
|
|
86
|
+
name.should == '/'
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
context "when we call get_resources_names function" do
|
|
92
|
+
it "returns all resources name" do
|
|
93
|
+
@routes_doc.add_route( 'GET /users(.:format) users#index' )
|
|
94
|
+
@routes_doc.add_route( 'GET /images(.:format) images#index' )
|
|
95
|
+
@routes_doc.get_resources_names.should == [ :images, :users ]
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
context "when we call get_resource_actions_names function" do
|
|
100
|
+
it "returns all actions names" do
|
|
101
|
+
@routes_doc.add_route( 'GET /users(.:format) users#index' )
|
|
102
|
+
@routes_doc.add_route( 'GET /users(.:format) users#show' )
|
|
103
|
+
@routes_doc.get_resource_actions_names( :users ).should == [ 'index', 'show' ]
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
context "when we call add_route function" do
|
|
108
|
+
before do
|
|
109
|
+
@route = 'GET /users(.:format) users#index'
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "calls add_resource_route function with correct params" do
|
|
113
|
+
@routes_doc.should_receive( :add_resource_route ).
|
|
114
|
+
with( 'GET', '/users(.:format)', 'users#index' )
|
|
115
|
+
@routes_doc.add_route( @route )
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
context "when we call get_action_info function" do
|
|
120
|
+
before do
|
|
121
|
+
@route = 'GET /users(.:format) users#index'
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it "returns correct Hash" do
|
|
125
|
+
@routes_doc.add_route( @route )
|
|
126
|
+
@routes_doc.get_action_route_info( :users, :index ).should == {
|
|
127
|
+
resource: 'users',
|
|
128
|
+
action: 'index',
|
|
129
|
+
method: 'GET',
|
|
130
|
+
urls: ['/users(.:format)'],
|
|
131
|
+
controllers: [ 'users' ]
|
|
132
|
+
}
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
context "when we call get_resource_actions_info function" do
|
|
137
|
+
before do
|
|
138
|
+
@routes_doc.add_route( 'GET /users(.:format) users#index' )
|
|
139
|
+
@routes_doc.add_route( 'GET /users(.:format) users#show' )
|
|
140
|
+
@actions_info = @routes_doc.get_actions_route_info( 'users' )
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "returns all actions info" do
|
|
144
|
+
@actions_info.should be_include(
|
|
145
|
+
@routes_doc.get_action_route_info( 'users', 'index' ) )
|
|
146
|
+
@actions_info.should be_include(
|
|
147
|
+
@routes_doc.get_action_route_info( 'users', 'show' ) )
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
include Rapidoc
|
|
4
|
+
|
|
5
|
+
describe TemplatesGenerator do
|
|
6
|
+
|
|
7
|
+
before :all do
|
|
8
|
+
create_structure
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
after :all do
|
|
12
|
+
remove_doc
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
context "when call generate_index_template" do
|
|
16
|
+
it "should create new index.html file" do
|
|
17
|
+
generate_index_template nil
|
|
18
|
+
File.exists?( target_dir + '/index.html' ).should == true
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context "when call get_index_template function" do
|
|
23
|
+
it "should return Handlebars Template " do
|
|
24
|
+
@template = get_index_template
|
|
25
|
+
@template.class.should == Handlebars::Template
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context "when call generate_actions_templates function" do
|
|
30
|
+
before do
|
|
31
|
+
@resources = get_resources.select{ |r| r.actions_doc }
|
|
32
|
+
generate_actions_templates @resources
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "should create new action.html file for each action"do
|
|
36
|
+
@resources.each do |resource|
|
|
37
|
+
resource.actions_doc.each do |action_doc|
|
|
38
|
+
route = actions_dir + "/#{resource.name}_#{action_doc.action}.html"
|
|
39
|
+
File.exists?( route ).should == true
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "when call create_action_template function" do
|
|
46
|
+
before do
|
|
47
|
+
extractor = ControllerExtractor.new "users_controller.rb"
|
|
48
|
+
resource_info = get_routes_doc.get_actions_route_info( :users )
|
|
49
|
+
|
|
50
|
+
info = resource_info.group_by{ |entrie| entrie[:action] }['create'].first
|
|
51
|
+
controller_info = extractor.get_action_info( 'create' )
|
|
52
|
+
@action_doc = ActionDoc.new( info, controller_info, examples_dir )
|
|
53
|
+
|
|
54
|
+
create_action_template( get_action_template, @action_doc )
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "should create new action html file" do
|
|
58
|
+
route = actions_dir + "/#{@action_doc.resource}_#{@action_doc.action}.html"
|
|
59
|
+
File.exists?( route ).should == true
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
context "when call get_action_template function" do
|
|
64
|
+
it "should return Handlebars Template " do
|
|
65
|
+
@template = get_action_template
|
|
66
|
+
@template.class.should == Handlebars::Template
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
context "when call get_method_label" do
|
|
71
|
+
context "when call with valid method" do
|
|
72
|
+
before do
|
|
73
|
+
@methods = [ 'GET', 'POST', 'PUT', 'DELETE' ]
|
|
74
|
+
@labels = [ 'label-info', 'label-success', 'label-warning', 'label-important' ]
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "should return correct label" do
|
|
78
|
+
@methods.each_index do |i|
|
|
79
|
+
get_method_label( @methods[i] ).should == 'label ' + @labels[i]
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
context "when call with unknow method" do
|
|
85
|
+
it "should return correct label" do
|
|
86
|
+
get_method_label( 'unknow' ).should == 'label'
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|