horse_power 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/horse_power/application.js +13 -0
  6. data/app/assets/stylesheets/horse_power/application.css +15 -0
  7. data/app/controllers/horse_power/application_controller.rb +4 -0
  8. data/app/helpers/horse_power/application_helper.rb +4 -0
  9. data/app/views/layouts/horse_power/application.html.erb +14 -0
  10. data/config/routes.rb +2 -0
  11. data/lib/generators/horse_power/app_environment/USAGE +8 -0
  12. data/lib/generators/horse_power/app_environment/app_environment_generator.rb +128 -0
  13. data/lib/generators/horse_power/authorization/USAGE +8 -0
  14. data/lib/generators/horse_power/authorization/authorization_generator.rb +20 -0
  15. data/lib/generators/horse_power/authorization/templates/auth_file.rb.erb +59 -0
  16. data/lib/generators/horse_power/controller/USAGE +8 -0
  17. data/lib/generators/horse_power/controller/controller_generator.rb +15 -0
  18. data/lib/generators/horse_power/controller/templates/controller_template.rb.erb +96 -0
  19. data/lib/generators/horse_power/make_admin/USAGE +8 -0
  20. data/lib/generators/horse_power/make_admin/make_admin_generator.rb +67 -0
  21. data/lib/generators/horse_power/make_admin/templates/dashboard.rb.erb +25 -0
  22. data/lib/generators/horse_power/make_admin/templates/defcon_admin_register.rb.erb +99 -0
  23. data/lib/generators/horse_power/model/USAGE +8 -0
  24. data/lib/generators/horse_power/model/model_generator.rb +21 -0
  25. data/lib/generators/horse_power/model/templates/model.rb.erb +5 -0
  26. data/lib/generators/horse_power/scaffold/USAGE +8 -0
  27. data/lib/generators/horse_power/scaffold/scaffold_generator.rb +54 -0
  28. data/lib/generators/horse_power/scaffold/templates/active_admin_register.rb.erb +6 -0
  29. data/lib/generators/horse_power/serializer/USAGE +8 -0
  30. data/lib/generators/horse_power/serializer/serializer_generator.rb +15 -0
  31. data/lib/generators/horse_power/serializer/templates/serializer.rb.erb +38 -0
  32. data/lib/generators/horse_power/setup/USAGE +8 -0
  33. data/lib/generators/horse_power/setup/setup_generator.rb +188 -0
  34. data/lib/generators/horse_power/setup/templates/active_admin_token_register.rb.erb +102 -0
  35. data/lib/generators/horse_power/setup/templates/app_index_controller.rb +6 -0
  36. data/lib/generators/horse_power/setup/templates/application_controller.rb +45 -0
  37. data/lib/generators/horse_power/setup/templates/hidden_rspec.rb +3 -0
  38. data/lib/generators/horse_power/setup/templates/json_helpers.rb +7 -0
  39. data/lib/generators/horse_power/setup/templates/rspec_factory_girl.rb +16 -0
  40. data/lib/generators/horse_power/setup/templates/views/app +0 -0
  41. data/lib/generators/horse_power/setup/templates/views/app_index +9 -0
  42. data/lib/generators/horse_power/tests/USAGE +8 -0
  43. data/lib/generators/horse_power/tests/templates/factory.rb.erb +12 -0
  44. data/lib/generators/horse_power/tests/templates/model.rb.erb +35 -0
  45. data/lib/generators/horse_power/tests/templates/request.rb.erb +136 -0
  46. data/lib/generators/horse_power/tests/templates/routing.rb.erb +46 -0
  47. data/lib/generators/horse_power/tests/tests_generator.rb +18 -0
  48. data/lib/generators/horse_power/user/USAGE +8 -0
  49. data/lib/generators/horse_power/user/templates/admin.rb.erb +20 -0
  50. data/lib/generators/horse_power/user/templates/authorization.rb.erb +97 -0
  51. data/lib/generators/horse_power/user/templates/controller.rb.erb +135 -0
  52. data/lib/generators/horse_power/user/templates/model.rb.erb +56 -0
  53. data/lib/generators/horse_power/user/templates/serializer.rb.erb +44 -0
  54. data/lib/generators/horse_power/user/templates/specs/factory.rb.erb +14 -0
  55. data/lib/generators/horse_power/user/templates/specs/model.rb.erb +61 -0
  56. data/lib/generators/horse_power/user/templates/specs/requests.rb.erb +220 -0
  57. data/lib/generators/horse_power/user/templates/specs/routing.rb.erb +58 -0
  58. data/lib/generators/horse_power/user/user_generator.rb +67 -0
  59. data/lib/horse_power/engine.rb +5 -0
  60. data/lib/horse_power/version.rb +3 -0
  61. data/lib/horse_power.rb +72 -0
  62. data/lib/tasks/horse_power_tasks.rake +4 -0
  63. data/test/dummy/README.rdoc +28 -0
  64. data/test/dummy/Rakefile +6 -0
  65. data/test/dummy/app/assets/javascripts/application.js +13 -0
  66. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  67. data/test/dummy/app/controllers/application_controller.rb +5 -0
  68. data/test/dummy/app/helpers/application_helper.rb +2 -0
  69. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  70. data/test/dummy/bin/bundle +3 -0
  71. data/test/dummy/bin/rails +4 -0
  72. data/test/dummy/bin/rake +4 -0
  73. data/test/dummy/config/application.rb +23 -0
  74. data/test/dummy/config/boot.rb +5 -0
  75. data/test/dummy/config/database.yml +25 -0
  76. data/test/dummy/config/environment.rb +5 -0
  77. data/test/dummy/config/environments/development.rb +37 -0
  78. data/test/dummy/config/environments/production.rb +78 -0
  79. data/test/dummy/config/environments/test.rb +39 -0
  80. data/test/dummy/config/initializers/assets.rb +8 -0
  81. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  82. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  83. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  84. data/test/dummy/config/initializers/inflections.rb +16 -0
  85. data/test/dummy/config/initializers/mime_types.rb +4 -0
  86. data/test/dummy/config/initializers/session_store.rb +3 -0
  87. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  88. data/test/dummy/config/locales/en.yml +23 -0
  89. data/test/dummy/config/routes.rb +4 -0
  90. data/test/dummy/config/secrets.yml +22 -0
  91. data/test/dummy/config.ru +4 -0
  92. data/test/dummy/public/404.html +67 -0
  93. data/test/dummy/public/422.html +67 -0
  94. data/test/dummy/public/500.html +66 -0
  95. data/test/dummy/public/favicon.ico +0 -0
  96. data/test/fresh/test_app/Gemfile +41 -0
  97. data/test/fresh/test_app/Gemfile.lock +127 -0
  98. data/test/fresh/test_app/README.rdoc +28 -0
  99. data/test/fresh/test_app/Rakefile +6 -0
  100. data/test/fresh/test_app/app/assets/javascripts/application.js +16 -0
  101. data/test/fresh/test_app/app/assets/stylesheets/application.css +15 -0
  102. data/test/fresh/test_app/app/controllers/application_controller.rb +5 -0
  103. data/test/fresh/test_app/app/helpers/application_helper.rb +2 -0
  104. data/test/fresh/test_app/app/views/layouts/application.html.erb +14 -0
  105. data/test/fresh/test_app/bin/bundle +3 -0
  106. data/test/fresh/test_app/bin/rails +8 -0
  107. data/test/fresh/test_app/bin/rake +8 -0
  108. data/test/fresh/test_app/bin/spring +18 -0
  109. data/test/fresh/test_app/config/application.rb +23 -0
  110. data/test/fresh/test_app/config/boot.rb +4 -0
  111. data/test/fresh/test_app/config/database.yml +25 -0
  112. data/test/fresh/test_app/config/environment.rb +5 -0
  113. data/test/fresh/test_app/config/environments/development.rb +37 -0
  114. data/test/fresh/test_app/config/environments/production.rb +78 -0
  115. data/test/fresh/test_app/config/environments/test.rb +39 -0
  116. data/test/fresh/test_app/config/initializers/assets.rb +8 -0
  117. data/test/fresh/test_app/config/initializers/backtrace_silencers.rb +7 -0
  118. data/test/fresh/test_app/config/initializers/cookies_serializer.rb +3 -0
  119. data/test/fresh/test_app/config/initializers/filter_parameter_logging.rb +4 -0
  120. data/test/fresh/test_app/config/initializers/inflections.rb +16 -0
  121. data/test/fresh/test_app/config/initializers/mime_types.rb +4 -0
  122. data/test/fresh/test_app/config/initializers/session_store.rb +3 -0
  123. data/test/fresh/test_app/config/initializers/wrap_parameters.rb +14 -0
  124. data/test/fresh/test_app/config/locales/en.yml +23 -0
  125. data/test/fresh/test_app/config/routes.rb +56 -0
  126. data/test/fresh/test_app/config/secrets.yml +22 -0
  127. data/test/fresh/test_app/config.ru +4 -0
  128. data/test/fresh/test_app/db/seeds.rb +7 -0
  129. data/test/fresh/test_app/public/404.html +67 -0
  130. data/test/fresh/test_app/public/422.html +67 -0
  131. data/test/fresh/test_app/public/500.html +66 -0
  132. data/test/fresh/test_app/public/favicon.ico +0 -0
  133. data/test/fresh/test_app/public/robots.txt +5 -0
  134. data/test/fresh/test_app/test/test_helper.rb +10 -0
  135. data/test/horse_power_test.rb +7 -0
  136. data/test/integration/navigation_test.rb +10 -0
  137. data/test/lib/generators/horse_power/app_environment_generator_test.rb +16 -0
  138. data/test/lib/generators/horse_power/authorization_generator_test.rb +16 -0
  139. data/test/lib/generators/horse_power/controller_generator_test.rb +16 -0
  140. data/test/lib/generators/horse_power/make_admin_generator_test.rb +16 -0
  141. data/test/lib/generators/horse_power/model_generator_test.rb +16 -0
  142. data/test/lib/generators/horse_power/scaffold_generator_test.rb +16 -0
  143. data/test/lib/generators/horse_power/serializer_generator_test.rb +16 -0
  144. data/test/lib/generators/horse_power/setup_generator_test.rb +16 -0
  145. data/test/lib/generators/horse_power/tests_generator_test.rb +16 -0
  146. data/test/lib/generators/horse_power/user_generator_test.rb +16 -0
  147. data/test/test_helper.rb +15 -0
  148. metadata +313 -0
@@ -0,0 +1,61 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe User, '.username', :type => :model do
4
+ it "does not save when nil" do
5
+ user = FactoryGirl.build(:user_1, :username => nil)
6
+ expect(user.save).to equal(false)
7
+ end
8
+ it "does not save with invalid characters" do
9
+ #user = FactoryGirl.build(:user_1, :username => "!@#$%)")
10
+ #expect(user.save).to equal(false)
11
+ end
12
+ end
13
+ RSpec.describe User, '.email', :type => :model do
14
+ it "does not save when nil" do
15
+ user = FactoryGirl.build(:user_1, :email => nil)
16
+ expect(user.save).to equal(false)
17
+ end
18
+ it "does not save with invalid characters" do
19
+ #user = FactoryGirl.build(:user_1, :email => "!@#$%)")
20
+ #expect(user.save).to equal(false)
21
+ end
22
+ end
23
+ RSpec.describe User, '.password_digest', :type => :model do
24
+ it "does not save when nil" do
25
+ user = FactoryGirl.build(:user_1, :password => nil, :password_confirmation => nil)
26
+ expect(user.save).to equal(false)
27
+ end
28
+ it "does not save when not a match" do
29
+ user = FactoryGirl.build(:user_1, :password => "firstAttempt", :password_confirmation => "secondAttempt")
30
+ expect(user.save).to equal(false)
31
+ end
32
+ it "saves with a matching password and password_confirmation" do
33
+ user = FactoryGirl.build(:user_1, :password => "good_password", :password_confirmation => "good_password")
34
+ expect(user.save).to equal(true)
35
+ end
36
+ end
37
+ RSpec.describe User, :type => :model do
38
+ describe "dependencies" do
39
+ before(:example) do
40
+ @user = FactoryGirl.create(:user_1)
41
+ end
42
+ it "deletes ... when deleted" do
43
+
44
+ end
45
+ end
46
+ end
47
+ RSpec.describe User, :type => :model do
48
+ describe "callbacks" do
49
+ before(:example) do
50
+ @user = FactoryGirl.create(:user_1)
51
+ end
52
+
53
+ it "creates an authentication token" do
54
+ expect(@user.tokens.any?).to equal(true)
55
+ end
56
+ it "does not create an empty auth token" do
57
+ expect(@user.tokens[0].auth_token.nil?).to equal(false)
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,220 @@
1
+ require "rails_helper"
2
+
3
+ #-#-#-#-#REST#-#-#-#-#
4
+ RSpec.describe User, :type => :request do
5
+ describe "Index" do
6
+ before(:example) do
7
+ @user = FactoryGirl.create(:user_1)
8
+ token = @user.tokens[0].auth_token
9
+ @header = {::Settings.token_header => token, "Email" => @user.email, ::Settings.main_api_header => ::Settings.main_api_key}
10
+ end
11
+ # get /api/1/users
12
+ it "checks index json response" do
13
+ FactoryGirl.create_list(:user_1, 10)
14
+ get 'api/1/users', nil, @header
15
+ expect(response.status).to eq(200) #ok
16
+ expect(json["users"]).to_not eq(nil)
17
+ end
18
+ end
19
+ end
20
+ RSpec.describe User, :type => :request do
21
+ describe "Show" do
22
+ before(:example) do
23
+ @user = FactoryGirl.create(:user_1)
24
+ token = @user.tokens[0].auth_token
25
+ @header = {::Settings.token_header => token, "Email" => @user.email, ::Settings.main_api_header => ::Settings.main_api_key}
26
+ end
27
+ # get /api/1/users/1
28
+ it "checks show json response" do
29
+ get "api/1/users/#{@user.id}", nil, @header
30
+ expect(response.status).to eq(200) #ok
31
+ expect(json["user"]["id"]).to eq(1)
32
+ end
33
+ end
34
+ end
35
+ RSpec.describe User, :type => :request do
36
+ describe "Update" do
37
+ before(:example) do
38
+ @user = FactoryGirl.create(:user_1)
39
+ token = @user.tokens[0].auth_token
40
+ @header = {::Settings.token_header => token, "Email" => @user.email, ::Settings.main_api_header => ::Settings.main_api_key}
41
+ @attrs = FactoryGirl.attributes_for(:user_1)
42
+ @attrs["email"] = @user.email
43
+ @attrs["username"] = @user.username
44
+ end
45
+ # put /api/1/users/1
46
+ it "checks update json response" do
47
+ @attrs["email"] = "cole@email.com"
48
+ hash = {"user" => @attrs}
49
+ #This uses users 1 header
50
+ put "api/1/users/#{@user.id}", hash, @header
51
+ expect(response.status).to eq(200) #ok
52
+ expect(json["user"]["email"]).to eq("cole@email.com")
53
+ end
54
+ it "makes sure a user cannot alter another users information" do
55
+ FactoryGirl.create(:user_1)
56
+ @attrs["email"] = "cole@email.com"
57
+ hash = {"user" => @attrs}
58
+ #This uses users 1 header and user 2 id
59
+ put "api/1/users/#{@user.id + 1}", hash, @header
60
+ expect(response.status).to eq(403) #forbidden
61
+ end
62
+ it "makes sure a user can't update to bad values" do
63
+ @attrs["email"] = ""
64
+ hash = {"user" => @attrs}
65
+ #This uses users 1 header
66
+ put "api/1/users/#{@user.id}", hash, @header
67
+ expect(response.status).to eq(422) #ok
68
+ end
69
+ end
70
+ end
71
+ RSpec.describe User, :type => :request do
72
+ describe "Destroy" do
73
+ before(:example) do
74
+ @user = FactoryGirl.create(:user_1)
75
+ token = @user.tokens[0].auth_token
76
+ @header = {::Settings.token_header => token, "Email" => @user.email, ::Settings.main_api_header => ::Settings.main_api_key}
77
+ @attrs = FactoryGirl.attributes_for(:user_1)
78
+ @attrs["email"] = @user.email
79
+ @attrs["username"] = @user.username
80
+ end
81
+ # delete /api/1/users/1
82
+ it "makes sure a user can delete their accout" do
83
+ hash = {"user" => @attrs}
84
+ #This uses users 1 header
85
+ delete "api/1/users/#{@user.id}", hash, @header
86
+ expect(response.status).to eq(200) #ok
87
+ expect(User.count).to eq(0)
88
+ end
89
+ # delete /api/1/users/2
90
+ it "makes sure a user can't delete another persons account" do
91
+ hash = {"user" => @attrs}
92
+ #This uses users 1 header
93
+ user2 = FactoryGirl.create(:user_1)
94
+ delete "api/1/users/#{user2.id}", hash, @header
95
+ expect(response.status).to eq(403) #ok
96
+ expect(User.count).to eq(2)
97
+ end
98
+ end
99
+ end
100
+ #-#-#-#-#Serialization#-#-#-#-#
101
+ RSpec.describe User, :type => :request do
102
+ describe "Serialization" do
103
+ before(:example) do
104
+ @user = FactoryGirl.create(:user_1)
105
+ token = @user.tokens[0].auth_token
106
+ @header = {::Settings.token_header => token, "Email" => @user.email, ::Settings.main_api_header => ::Settings.main_api_key}
107
+ end
108
+ # get /api/1/users
109
+ it "checks only appropriate attributes are sent back for index" do
110
+ FactoryGirl.create_list(:user_1, 10)
111
+ get 'api/1/users', nil, @header
112
+ expect(response.status).to eq(200) #ok
113
+ expect(User.count).to eq(11)
114
+ expect(::Arcadex::Token.count).to eq(11)
115
+ expect(json["users"][0]["password_digest"]).to eq(nil)
116
+ expect(json["users"][0]["created_at"]).to_not eq(nil)
117
+ expect(json["users"][0]["updated_at"]).to_not eq(nil)
118
+ end
119
+ end
120
+ end
121
+ #-#-#-#-#Errors#-#-#-#-#
122
+ RSpec.describe User, :type => :request do
123
+ describe "Authorization" do
124
+ before(:example) do
125
+ @user = FactoryGirl.create(:user_1)
126
+ token = @user.tokens[0].auth_token
127
+ @header = {::Settings.token_header => token, "Email" => @user.email, ::Settings.main_api_header => ::Settings.main_api_key}
128
+ end
129
+ it "checks for 404 response" do
130
+ get "api/1/users/#{@user.id + 10}", nil, @header
131
+ expect(response.status).to eq(404) #not_found
132
+ end
133
+ end
134
+ end
135
+ #-#-#-#-#Collection Routes#-#-#-#-#
136
+ #-#-#-#-#Authentication#-#-#-#-#
137
+ RSpec.describe User, :type => :request do
138
+ describe "Register" do
139
+ before(:example) do
140
+ @attrs = FactoryGirl.attributes_for(:user_1)
141
+ @header = {::Settings.main_api_header => ::Settings.main_api_key}
142
+ end
143
+ # post /api/1/users/register
144
+ it "checks response of a register request with a valid user object" do
145
+ hash = {"user" => @attrs}
146
+ post 'api/1/users/register', hash, @header
147
+ expect(response.status).to eq(200) #ok
148
+ expect(User.all.count).to eq(1)
149
+ #A valid token needs to be returned
150
+ expect(json["token"]["auth_token"]).to_not eq(nil)
151
+ token = User.find(1).tokens[0]
152
+ expect(json["token"]["auth_token"]).to eq(token.auth_token)
153
+ end
154
+ # post /api/1/users/register
155
+ it "checks response of a register request with mismatched passwords" do
156
+ @attrs["password"] = "password1"
157
+ @attrs["password_confirmation"] = "password2"
158
+ hash = {"user" => @attrs}
159
+ post 'api/1/users/register', hash, @header
160
+ expect(response.status).to eq(422) #invalid_resource
161
+ expect(User.all.count).to eq(0)
162
+ #Errors need to be returned
163
+ expect(json["errors"]).to_not eq(nil)
164
+ end
165
+ end
166
+ end
167
+ RSpec.describe User, :type => :request do
168
+ describe "Login" do
169
+ before(:example) do
170
+ @attrs = FactoryGirl.attributes_for(:user_1)
171
+ @header = {::Settings.main_api_header => ::Settings.main_api_key}
172
+ end
173
+ # post /api/1/users/login
174
+ it "checks response of a valid login request" do
175
+ @attrs["password"] = "password123"
176
+ @attrs["password_confirmation"] = "password123"
177
+ user = FactoryGirl.create(:user_1,@attrs)
178
+ old_auth_token = user.tokens[0].auth_token
179
+ hash = {"user" => @attrs}
180
+ post 'api/1/users/login', hash, @header
181
+ expect(response.status).to eq(200) #ok
182
+ #A valid and new token need to be returned
183
+ expect(json["token"]["auth_token"]).to_not eq(old_auth_token)
184
+ #This token should be the newest token in the database
185
+ new_auth_token = User.find(1).tokens.order("created_at").last.auth_token
186
+ expect(json["token"]["auth_token"]).to eq(new_auth_token)
187
+ end
188
+ # post /api/1/users/login
189
+ it "checks response of an invalid login request with an invalid password" do
190
+ @attrs["password"] = "password123"
191
+ @attrs["password_confirmation"] = "password123"
192
+ user = FactoryGirl.create(:user_1,@attrs)
193
+ #The password needs to be invalid
194
+ @attrs["password"] = "wrongPassword"
195
+ hash = {"user" => @attrs}
196
+ #It needs to send an email and password
197
+ post 'api/1/users/login', hash, @header
198
+ expect(response.status).to eq(401) #unauthorized
199
+ #Errors need to be returned
200
+ expect(json["errors"]).to_not eq(nil)
201
+ end
202
+ end
203
+ end
204
+ RSpec.describe User, :type => :request do
205
+ describe "Logout" do
206
+ before(:example) do
207
+ @attrs = FactoryGirl.attributes_for(:user_1)
208
+ end
209
+ # get /api/1/users/1/logout
210
+ it "checks logout response and makes sure token is deleted" do
211
+ user = FactoryGirl.create(:user_1,@attrs)
212
+ token = user.tokens[0].auth_token
213
+ header = {::Settings.token_header => token, "Email" => user.email, ::Settings.main_api_header => ::Settings.main_api_key}
214
+ post 'api/1/users/logout', nil, header
215
+ expect(User.count).to eq(1)
216
+ expect(response.status).to eq(200) #ok
217
+ expect(::Arcadex::Token.count).to eq(0)
218
+ end
219
+ end
220
+ end
@@ -0,0 +1,58 @@
1
+ require "rails_helper"
2
+
3
+ #The standard rest routes for the user controller
4
+ RSpec.describe "Users controller rest routing", :type => :routing do
5
+
6
+ it "routes to index" do
7
+ expect(:get => "/api/1/users").to route_to(
8
+ :controller => "api/v1/users",
9
+ :action => "index"
10
+ )
11
+ end
12
+ it "routes to show" do
13
+ expect(:get => "/api/1/users/1").to route_to(
14
+ :controller => "api/v1/users",
15
+ :action => "show",
16
+ :id => "1"
17
+ )
18
+ end
19
+ it "routes to update" do
20
+ expect(:put => "/api/1/users/1/").to route_to(
21
+ :controller => "api/v1/users",
22
+ :action => "update",
23
+ :id => "1"
24
+ )
25
+ end
26
+ it "routes to update" do
27
+ expect(:patch => "/api/1/users/1/").to route_to(
28
+ :controller => "api/v1/users",
29
+ :action => "update",
30
+ :id => "1"
31
+ )
32
+ end
33
+ it "routes to delete" do
34
+ expect(:delete => "/api/1/users/1/").to route_to(
35
+ :controller => "api/v1/users",
36
+ :action => "destroy",
37
+ :id => "1"
38
+ )
39
+ end
40
+ it "routes create to register" do
41
+ expect(:post => "/api/1/users/register").to route_to(
42
+ :controller => "api/v1/users",
43
+ :action => "register"
44
+ )
45
+ end
46
+ it "routes create to login" do
47
+ expect(:post => "/api/1/users/login").to route_to(
48
+ :controller => "api/v1/users",
49
+ :action => "login"
50
+ )
51
+ end
52
+ it "routes create to logout" do
53
+ expect(:post => "/api/1/users/logout").to route_to(
54
+ :controller => "api/v1/users",
55
+ :action => "logout"
56
+ )
57
+ end
58
+ end
@@ -0,0 +1,67 @@
1
+ module HorsePower
2
+ class UserGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def sprint
6
+ create_migration
7
+ create_model
8
+ create_controller
9
+ create_authorization
10
+ create_serializer
11
+ create_admin
12
+ create_tests
13
+ create_routes
14
+ end
15
+
16
+ private
17
+
18
+ def create_migration
19
+ run "rails g model user username:string:uniq email:string:uniq password_digest:string --no-fixture --skip"
20
+ run "rm -rf app/models/user.rb"
21
+ run "rm -rf spec/models/user_spec.rb"
22
+ run "rm -rf spec/factories/users.rb"
23
+ end
24
+
25
+ def create_model
26
+ template "model.rb.erb", "app/models/user.rb"
27
+ end
28
+
29
+ def create_controller
30
+ template "controller.rb.erb", "app/controllers/api/v1/users_controller.rb"
31
+ end
32
+
33
+ def create_authorization
34
+ template "authorization.rb.erb", "gems/authorization/lib/authorization/v1/user.rb"
35
+ prepend_file 'gems/authorization/lib/authorization.rb', "require \'authorization/v1/user\'\n"
36
+ end
37
+
38
+ def create_serializer
39
+ template "serializer.rb.erb", "app/serializers/v1/user_serializer.rb"
40
+ end
41
+
42
+ def create_admin
43
+ template "admin.rb.erb", "app/admin/user.rb"
44
+ end
45
+
46
+ def create_tests
47
+ template "specs/model.rb.erb", "spec/api/v1/models/user_spec.rb"
48
+ template "specs/routing.rb.erb", "spec/api/v1/routing/user_spec.rb"
49
+ template "specs/factory.rb.erb", "spec/factories/user_1_factory.rb"
50
+ template "specs/requests.rb.erb", "spec/api/v1/requests/user_spec.rb"
51
+ end
52
+
53
+ def create_routes
54
+ inject_into_file "config/routes.rb", after: "scope '1' do\n" do <<-'RUBY'
55
+ resources :users, except: [:new, :edit, :create], controller: 'api/v1/users' do
56
+ collection do
57
+ post 'register', to: "api/v1/users#register"
58
+ post 'login', to: "api/v1/users#login"
59
+ post 'logout', to: "api/v1/users#logout"
60
+ end
61
+ end
62
+ RUBY
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,5 @@
1
+ module HorsePower
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace HorsePower
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module HorsePower
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,72 @@
1
+ require "horse_power/engine"
2
+
3
+ module HorsePower
4
+
5
+ def self.params_list(attributes)
6
+ params = []
7
+ attributes.each do |pair|
8
+ elem = pair.split(/:/)[0]
9
+ field = ":#{elem}"
10
+ params << field
11
+ end
12
+ return params.join(",")
13
+ end
14
+
15
+ def self.get_column(pair)
16
+ return pair.split(/:/)[0]
17
+ end
18
+
19
+ def self.get_type(pair)
20
+ return pair.split(/:/)[1]
21
+ end
22
+
23
+ def self.get_singular(resource)
24
+ return resource.underscore.singularize
25
+ end
26
+
27
+ def self.get_plural(resource)
28
+ return resource.underscore.pluralize
29
+ end
30
+
31
+ def self.get_camel(resource)
32
+ return resource.camelize.singularize
33
+ end
34
+
35
+ def self.get_camel_plural(resource)
36
+ return self.get_camel(resource).pluralize
37
+ end
38
+
39
+ def self.default_values(field1)
40
+ field = field1.downcase
41
+ if field == "integer"
42
+ return 1
43
+ end
44
+ if field == "boolean"
45
+ return true
46
+ end
47
+ if field == "string"
48
+ return "\"Default String\""
49
+ end
50
+ if field == "text"
51
+ return "\"Default Text\""
52
+ end
53
+ if field == "float"
54
+ return 3.14
55
+ end
56
+ if field == "decimal"
57
+ return 3.14159
58
+ end
59
+ if field == "date"
60
+ return "\"#{Date.new}\""
61
+ end
62
+ if field == "time"
63
+ return "\"#{Time.new}\""
64
+ end
65
+ if field == "datetime"
66
+ return "\"#{DateTime.new}\""
67
+ end
68
+ #If there are any values that I missed
69
+ return nil
70
+ end
71
+
72
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :horse_power do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require "horse_power"
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
+ # config.time_zone = 'Central Time (US & Canada)'
17
+
18
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
+ # config.i18n.default_locale = :de
21
+ end
22
+ end
23
+
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ #
7
+ default: &default
8
+ adapter: sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ development:
13
+ <<: *default
14
+ database: db/development.sqlite3
15
+
16
+ # Warning: The database defined as "test" will be erased and
17
+ # re-generated from your development database when you run "rake".
18
+ # Do not set this db to the same as development or production.
19
+ test:
20
+ <<: *default
21
+ database: db/test.sqlite3
22
+
23
+ production:
24
+ <<: *default
25
+ database: db/production.sqlite3
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!