rammer 1.1.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/Gemfile +27 -0
  2. data/MODULE_FILES +34 -0
  3. data/README.md +17 -5
  4. data/Rakefile +37 -0
  5. data/bin/rammer +2 -3
  6. data/bin/viber +37 -38
  7. data/lib/modules/authentication/authentication_apis.rb +64 -0
  8. data/lib/modules/authorization/authorization_apis.rb +89 -0
  9. data/lib/modules/common/Gemfile +43 -0
  10. data/lib/{template → modules/common}/Gemfile.lock +0 -0
  11. data/lib/{template → modules/common}/Procfile +0 -0
  12. data/lib/{template → modules/common}/Rakefile +27 -0
  13. data/lib/modules/common/application.rb +48 -0
  14. data/lib/{template → modules/common}/database.yml +1 -1
  15. data/lib/modules/common/server.rb +38 -0
  16. data/lib/modules/common/tree.rb +30 -0
  17. data/lib/{template → modules/migrations}/01_create_users.rb +27 -0
  18. data/lib/modules/migrations/02_create_sessions.rb +36 -0
  19. data/lib/modules/migrations/03_create_owners.rb +40 -0
  20. data/lib/modules/migrations/04_create_oauth2_authorizations.rb +50 -0
  21. data/lib/modules/migrations/05_create_oauth2_clients.rb +45 -0
  22. data/lib/modules/models/oauth2_authorization.rb +203 -0
  23. data/lib/modules/models/oauth2_client.rb +216 -0
  24. data/lib/modules/models/owner.rb +65 -0
  25. data/lib/modules/models/session.rb +30 -0
  26. data/lib/modules/models/user.rb +135 -0
  27. data/lib/modules/oauth/oauth_apis.rb +92 -0
  28. data/lib/rammer/module_generator.rb +236 -0
  29. data/lib/rammer/rammer_generator.rb +160 -0
  30. data/lib/rammer/version.rb +28 -1
  31. data/lib/rammer.rb +24 -278
  32. data/rammer.gemspec +37 -24
  33. data/test/helper.rb +49 -0
  34. data/test/test_rammer_root_structure.rb +80 -0
  35. data/test/test_viber_module_plugin.rb +104 -0
  36. data/test/test_viber_module_unplug.rb +87 -0
  37. metadata +77 -29
  38. data/lib/template/02_create_sessions.rb +0 -9
  39. data/lib/template/03_create_owners.rb +0 -13
  40. data/lib/template/04_create_oauth2_authorizations.rb +0 -23
  41. data/lib/template/05_create_oauth2_clients.rb +0 -18
  42. data/lib/template/Gemfile +0 -16
  43. data/lib/template/application.rb +0 -21
  44. data/lib/template/authentication_apis.rb +0 -35
  45. data/lib/template/authorization_apis.rb +0 -59
  46. data/lib/template/oauth2_authorization.rb +0 -113
  47. data/lib/template/oauth2_client.rb +0 -100
  48. data/lib/template/oauth_apis.rb +0 -138
  49. data/lib/template/owner.rb +0 -10
  50. data/lib/template/server.rb +0 -11
  51. data/lib/template/session.rb +0 -3
  52. data/lib/template/tree.rb +0 -3
  53. data/lib/template/user.rb +0 -78
data/lib/rammer.rb CHANGED
@@ -1,287 +1,33 @@
1
- require "rammer/version"
2
- require 'fileutils'
3
- $gem_file_name = "rammer-"+Rammer::VERSION
4
- module Rammer
5
-
6
- class Generator
7
- attr_accessor :target_dir, :project_name, :module_name, :gem_path
8
- BASE_DIR = ['app', 'app/apis', 'config', 'db', 'db/migrate', 'app/models']
9
- TEMPLATE_FILES = ['Gemfile','Gemfile.lock','Procfile','Rakefile','server.rb', 'tree.rb']
10
- def initialize(dir_name)
11
- self.project_name = dir_name
12
- if self.project_name.nil? || self.project_name.squeeze.strip == ""
13
- raise NoGitHubRepoNameGiven
14
- else
15
- path = File.split(self.project_name)
16
-
17
- if path.size > 1
18
- extracted_directory = File.join(path[0..-1])
19
- self.project_name = path.last
20
- end
21
- end
22
- self.target_dir = self.project_name
23
- path = `gem which rammer`
24
- self.gem_path = path.split($gem_file_name,2).first
25
- end
26
-
27
- def run
28
- unless File.exists?(target_dir) || File.directory?(target_dir)
29
- $stdout.puts "Creating goliath application under the directory #{target_dir}"
30
- FileUtils.mkdir target_dir
31
- create_base_dirs
32
- copy_files_to_target
33
- setup_api_module
34
- copy_files_to_dir 'application.rb','config'
35
- copy_files_to_dir 'database.yml','config'
36
- $stdout.puts "\e[33mRun `bundle install` to install missing gems.\e[0m"
37
- else
38
- $stdout.puts "\e[1;31mError:\e[0m The directory #{target_dir} already exists, aborting. Maybe move it out of the way before continuing."
39
- end
40
- end
41
-
42
- private
43
-
44
- def create_base_dirs
45
- BASE_DIR.each do |dir|
46
- FileUtils.mkdir "#{target_dir}/#{dir}"
47
- $stdout.puts "\e[1;32m \tcreate\e[0m\t#{dir}"
48
- end
49
- FileUtils.mkdir "#{target_dir}/app/apis/#{target_dir}"
50
- $stdout.puts "\e[1;32m \tcreate\e[0m\tapp/apis/#{target_dir}"
51
- end
52
-
53
- def setup_api_module
54
- self.module_name = target_dir.split('_').map(&:capitalize).join('')
55
- create_api_module
56
- config_server
57
- end
58
-
59
- def create_api_module
60
- File.open("#{target_dir}/app/apis/#{target_dir}/base.rb", "w") do |f|
61
- f.write('module ')
62
- f.puts(module_name)
63
- f.write("\tclass Base < Grape::API\n\tend\nend")
64
- end
65
- $stdout.puts "\e[1;32m \tcreate\e[0m\tapp/apis/#{target_dir}/base.rb"
66
- end
67
-
68
- def config_server
69
- file = File.open("#{target_dir}/server.rb", "r+")
70
- file.each do |line|
71
- while line == "\tdef response(env)\n" do
72
- pos = file.pos
73
- rest = file.read
74
- file.seek pos
75
- file.write("\t\t::")
76
- file.write(module_name)
77
- file.write("::Base.call(env)\n")
78
- file.write(rest)
79
- return
80
- end
81
- end
82
- $stdout.puts "\e[1;32m \tcreate\e[0m\tserver.rb"
83
- end
84
-
85
- def copy_files_to_target
86
- TEMPLATE_FILES.each do |file|
87
- source = File.join("#{gem_path}/#{$gem_file_name}/lib/template/",file)
88
- FileUtils.cp(source,"#{target_dir}")
89
- $stdout.puts "\e[1;32m \tcreate\e[0m\t#{file}"
90
- end
91
- end
1
+ =begin
2
+ **************************************************************************
3
+ * The MIT License (MIT)
92
4
 
93
- def copy_files_to_dir(file,destination)
94
- FileUtils.cp("#{gem_path}/#{$gem_file_name}/lib/template/#{file}","#{target_dir}/#{destination}")
95
- $stdout.puts "\e[1;32m \tcreate\e[0m\t#{destination}/#{file}"
96
- end
97
- end
5
+ * Copyright (c) 2013-2014 QBurst Technologies Inc.
98
6
 
99
- class ModuleGenerator
100
- attr_accessor :target_dir, :module_class, :options, :module_name, :gem_path, :action
101
- AUTH_MIGRATE = ['01_create_users.rb','02_create_sessions.rb']
102
- OAUTH_MIGRATE = ['03_create_owners.rb', '04_create_oauth2_authorizations.rb', '05_create_oauth2_clients.rb']
103
- AUTH_MODELS = ['user.rb', 'session.rb', 'oauth2_authorization.rb']
104
- OAUTH_MODELS = ['oauth2_client.rb', 'owner.rb']
105
- def initialize(options)
106
- self.options = options
107
- self.target_dir = options[:target_dir]
108
- self.module_class = options[:module_class]
109
- self.module_name = options[:module_name]
110
- self.action = options[:action]
111
- path = `gem which rammer`
112
- self.gem_path = path.split($gem_file_name,2).first
113
- end
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
114
13
 
115
- def run
116
- case action
117
- when "-p","-plugin"
118
- flag = require_module_to_base
119
- mount_module unless flag
120
- copy_module
121
- create_migrations
122
- copy_model_files
123
- add_gems
124
- oauth_message if module_name == "oauth" && !flag
125
- when "-u","-unplug"
126
- unmount_module
127
- end
128
- end
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
129
16
 
130
- def mount_module
131
- file = File.open("#{Dir.pwd}/app/apis/#{target_dir}/base.rb", "r+")
132
- file.each do |line|
133
- while line == "\tclass Base < Grape::API\n" do
134
- pos = file.pos
135
- rest = file.read
136
- file.seek pos
137
- file.write("\t\tmount ")
138
- file.puts(module_class)
139
- file.write(rest)
140
- break
141
- end
142
- end
143
- $stdout.puts "\e[1;35m\tmounted\e[0m\t#{module_class}"
144
- end
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
145
24
 
146
- def require_module_to_base
147
- file = File.open("#{Dir.pwd}/app/apis/#{target_dir}/base.rb", "r+")
148
- file.each do |line|
149
- while line == "require_relative './modules/#{module_name}_apis'\n" do
150
- $stdout.puts "\e[33mModule already mounted.\e[0m"
151
- return true
152
- end
153
- end
154
- File.open("#{Dir.pwd}/app/apis/#{target_dir}/base.rb", "r+") do |f|
155
- pos = f.pos
156
- rest = f.read
157
- f.seek pos
158
- f.write("require_relative './modules/")
159
- f.write(module_name)
160
- f.write("_apis'\n")
161
- f.write(rest)
162
- end
163
- return false
164
- end
25
+ **************************************************************************
26
+ =end
165
27
 
166
- def copy_module
167
- src = "#{gem_path}/#{$gem_file_name}/lib/template/#{module_name}_apis.rb"
168
- dest = "#{Dir.pwd}/app/apis/#{target_dir}/modules"
169
- presence = File.exists?("#{dest}/#{module_name}_apis.rb")? true : false
170
- FileUtils.mkdir dest unless File.exists?(dest)
171
- FileUtils.cp(src,dest) unless presence
172
- configure_module_files
173
- $stdout.puts "\e[1;32m \tcreate\e[0m\tapp/apis/#{target_dir}/modules/#{module_name}_apis.rb" unless presence
174
- end
28
+ require "rammer/rammer_generator"
29
+ require "rammer/module_generator"
175
30
 
176
- def create_migrations
177
- src = "#{gem_path}/#{$gem_file_name}/lib/template"
178
- dest = "#{Dir.pwd}/db/migrate"
179
- case module_name
180
- when "authentication", "authorization"
181
- common_migrations(src,dest)
182
- when "oauth"
183
- common_migrations(src,dest)
184
- OAUTH_MIGRATE.each do |file|
185
- presence = File.exists?("#{dest}/#{file}")? true : false
186
- unless presence
187
- FileUtils.cp("#{src}/#{file}",dest)
188
- $stdout.puts "\e[1;32m \tcreate\e[0m\tdb/migrate/#{file}"
189
- end
190
- end
191
- end
192
- end
193
-
194
- def common_migrations(src,dest)
195
- AUTH_MIGRATE.each do |file|
196
- presence = File.exists?("#{dest}/#{file}")? true : false
197
- unless presence
198
- FileUtils.cp("#{src}/#{file}",dest)
199
- $stdout.puts "\e[1;32m \tcreate\e[0m\tdb/migrate/#{file}"
200
- end
201
- end
202
- end
203
-
204
- def common_models(src,dest)
205
- AUTH_MODELS.each do |file|
206
- presence = File.exists?("#{dest}/#{file}")? true : false
207
- unless presence
208
- FileUtils.cp("#{src}/#{file}",dest)
209
- $stdout.puts "\e[1;32m \tcreate\e[0m\tapp/models/#{file}"
210
- end
211
- end
212
- end
213
-
214
- def copy_model_files
215
- src = "#{gem_path}/#{$gem_file_name}/lib/template"
216
- dest = "#{Dir.pwd}/app/models"
217
- case module_name
218
- when "authentication", "authorization"
219
- common_models(src,dest)
220
- when "oauth"
221
- common_models(src,dest)
222
- OAUTH_MODELS.each do |file|
223
- presence = File.exists?("#{dest}/#{file}")? true : false
224
- unless presence
225
- FileUtils.cp("#{src}/#{file}",dest)
226
- $stdout.puts "\e[1;32m \tcreate\e[0m\tapp/models/#{file}"
227
- end
228
- end
229
- end
230
- end
231
-
232
- def configure_module_files
233
- file = File.read("#{Dir.pwd}/app/apis/#{target_dir}/modules/#{module_name}_apis.rb")
234
- replace = file.gsub(/module Rammer/, "module #{target_dir.split('_').map(&:capitalize)*''}")
235
- File.open("#{Dir.pwd}/app/apis/#{target_dir}/modules/#{module_name}_apis.rb", "w"){|f|
236
- f.puts replace
237
- }
238
- end
239
-
240
- def add_gems
241
- file = File.open("#{Dir.pwd}/Gemfile", "r+")
242
- file.each do |line|
243
- while line == "gem 'oauth2'\n" do
244
- return
245
- end
246
- end
247
- File.open("#{Dir.pwd}/Gemfile", "a+") do |f|
248
- f.write("gem 'multi_json'\ngem 'oauth2'\ngem 'songkick-oauth2-provider'\ngem 'ruby_regex'\ngem 'oauth'\n")
249
- end
250
- $stdout.puts "\e[1;35m \tGemfile\e[0m\tgem 'multi_json'\n\t\tgem 'oauth2'
251
- \t\tgem 'songkick-oauth2-provider'\n\t\tgem 'ruby_regex'\n\t\tgem 'oauth'\n"
252
- $stdout.puts "\e[1;32m \trun\e[0m\tbundle install"
253
- system("bundle install")
254
- end
255
-
256
- def unmount_module
257
- temp_file = "#{Dir.pwd}/app/apis/#{target_dir}/tmp.rb"
258
- source = "#{Dir.pwd}/app/apis/#{target_dir}/base.rb"
259
- delete_file = "#{Dir.pwd}/app/apis/#{target_dir}/modules/#{module_name}_apis.rb"
260
- File.open(temp_file, "w") do |out_file|
261
- File.foreach(source) do |line|
262
- unless line == "require_relative './modules/#{module_name}_apis'\n"
263
- out_file.puts line unless line == "\t\tmount #{module_class}\n"
264
- end
265
- end
266
- FileUtils.mv(temp_file, source)
267
- end
268
- if File.exists?(delete_file)
269
- FileUtils.rm(delete_file)
270
- $stdout.puts "\e[1;35m\tunmounted\e[0m\t#{module_class}"
271
- $stdout.puts "\e[1;31m\tdelete\e[0m\t\tapp/apis/#{target_dir}/modules/#{module_name}_apis.rb"
272
- else
273
- $stdout.puts "\e[33mModule already unmounted.\e[0m"
274
- end
275
- end
276
-
277
- def oauth_message
278
- $stdout.puts "\e[33m
279
- In app/apis/<APP_NAME>/modules/oauth_apis.rb
280
- Specify redirection url to the respective authorization page into 'redirect_to_url'
281
- and uncomment the code to enable /oauth/authorize endpoint functionality.
282
-
283
- \e[0m"
284
- end
285
- end
31
+ module Rammer
286
32
  end
287
33
 
data/rammer.gemspec CHANGED
@@ -1,6 +1,37 @@
1
1
  # coding: utf-8
2
+
3
+ =begin
4
+ **************************************************************************
5
+ * The MIT License (MIT)
6
+
7
+ * Copyright (c) 2013-2014 QBurst Technologies Inc.
8
+
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+
16
+ * The above copyright notice and this permission notice shall be included in
17
+ * all copies or substantial portions of the Software.
18
+
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ * THE SOFTWARE.
26
+
27
+ **************************************************************************
28
+ =end
29
+
2
30
  lib = File.expand_path('../lib', __FILE__)
3
31
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
32
+ modules = File.expand_path('../MODULE_FILES', __FILE__)
33
+ $module_files = File.foreach(modules).map { |line| line.split("\n") }
34
+
4
35
  require 'rammer/version'
5
36
 
6
37
  Gem::Specification.new do |spec|
@@ -13,39 +44,21 @@ Gem::Specification.new do |spec|
13
44
  spec.homepage = "http://github.com/qburstruby/rammer"
14
45
  spec.license = "MIT"
15
46
 
16
- spec.files = ["lib/rammer.rb",
17
- "lib/rammer/version.rb",
18
- "lib/template/01_create_users.rb",
19
- "lib/template/02_create_sessions.rb",
20
- "lib/template/03_create_owners.rb",
21
- "lib/template/04_create_oauth2_authorizations.rb",
22
- "lib/template/05_create_oauth2_clients.rb",
23
- "lib/template/Gemfile",
24
- "lib/template/Gemfile.lock",
25
- "lib/template/Procfile",
26
- "lib/template/Rakefile",
27
- "lib/template/application.rb",
28
- "lib/template/authentication_apis.rb",
29
- "lib/template/authorization_apis.rb",
30
- "lib/template/database.yml",
31
- "lib/template/oauth2_authorization.rb",
32
- "lib/template/oauth2_client.rb",
33
- "lib/template/oauth_apis.rb",
34
- "lib/template/owner.rb",
35
- "lib/template/server.rb",
36
- "lib/template/session.rb",
37
- "lib/template/tree.rb",
38
- "lib/template/user.rb",
47
+ spec.files = [
39
48
  "Gemfile",
40
49
  "LICENSE.txt",
41
50
  "README.md",
42
51
  "Rakefile",
52
+ "MODULE_FILES",
43
53
  "rammer.gemspec"
44
54
  ]
55
+ spec.files += $module_files.each {|file| file}
45
56
  spec.executables = ["rammer","viber"]
46
57
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
47
58
  spec.require_paths = ["lib"]
48
59
 
49
- spec.add_development_dependency "bundler", "~> 1.4"
60
+ spec.add_development_dependency "bundler", "~> 1.4.0.rc.1"
50
61
  spec.add_development_dependency "rake"
62
+ spec.add_development_dependency "shoulda"
63
+ spec.add_development_dependency "simplecov"
51
64
  end
data/test/helper.rb ADDED
@@ -0,0 +1,49 @@
1
+ =begin
2
+ **************************************************************************
3
+ * The MIT License (MIT)
4
+
5
+ * Copyright (c) 2013-2014 QBurst Technologies Inc.
6
+
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+
25
+ **************************************************************************
26
+ =end
27
+
28
+ require 'simplecov'
29
+ SimpleCov.start
30
+
31
+ require 'rubygems'
32
+ require 'bundler'
33
+ begin
34
+ Bundler.setup(:default, :development)
35
+ rescue Bundler::BundlerError => e
36
+ $stderr.puts e.message
37
+ $stderr.puts "Run `bundle install` to install missing gems"
38
+ exit e.status_code
39
+ end
40
+ require 'test/unit'
41
+ require 'shoulda'
42
+
43
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
44
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
45
+ require 'rammer'
46
+ require 'fileutils'
47
+
48
+ class Test::Unit::TestCase
49
+ end
@@ -0,0 +1,80 @@
1
+ =begin
2
+ **************************************************************************
3
+ * The MIT License (MIT)
4
+
5
+ * Copyright (c) 2013-2014 QBurst Technologies Inc.
6
+
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+
25
+ **************************************************************************
26
+ =end
27
+
28
+ require_relative './helper'
29
+
30
+ $test_file = "dummy"
31
+ $test_file_root = "#{Dir.pwd}/test"
32
+
33
+ class TestRammerRootStructure < Test::Unit::TestCase
34
+
35
+ DIR = ['app', 'app/apis', 'config', 'db', 'db/migrate', 'app/models']
36
+ FILES = ['Gemfile','Gemfile.lock','Procfile','Rakefile','server.rb', 'tree.rb',
37
+ "app/apis/#{$test_file}/base.rb", 'config/application.rb', 'config/database.yml']
38
+
39
+ def test_generator_directory_name
40
+ Dir.chdir("#{$test_file_root}")
41
+ dir_path = Dir.pwd
42
+ generator = Rammer::RammerGenerator.new(" ")
43
+ generator.run
44
+ assert_equal(false, File.directory?("#{dir_path}/ "))
45
+ end
46
+
47
+ def test_generator_reserved_directory_name
48
+ dir_path = Dir.pwd
49
+ generator = Rammer::RammerGenerator.new("rammer")
50
+ generator.run
51
+ expected_valid_name_attr = false
52
+ assert_equal(expected_valid_name_attr, generator.valid_name)
53
+ end
54
+
55
+ def test_generator_root_directory
56
+ dir_path = Dir.pwd
57
+ FileUtils.rm_r "#{dir_path}/#{$test_file}" if File.directory?("#{dir_path}/#{$test_file}")
58
+ generator = Rammer::RammerGenerator.new("#{$test_file}")
59
+ generator.run
60
+ expected_root = "#{dir_path}/#{$test_file}"
61
+ assert_equal(expected_root, generator.target_dir)
62
+ end
63
+
64
+ def test_generator_root_directory_exisiting
65
+ dir_path = Dir.pwd
66
+ generator = Rammer::RammerGenerator.new("#{$test_file}")
67
+ generator.run
68
+ assert_equal(true, File.directory?("#{dir_path}/#{$test_file}"))
69
+ end
70
+
71
+ def test_generator_root_folder_structure
72
+ dir_path = Dir.pwd
73
+ DIR.each do |dir|
74
+ assert_equal(true, File.directory?("#{dir_path}/#{$test_file}/#{dir}"))
75
+ end
76
+ FILES.each do |file|
77
+ assert_equal(true, File.file?("#{dir_path}/#{$test_file}/#{file}"))
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,104 @@
1
+ =begin
2
+ **************************************************************************
3
+ * The MIT License (MIT)
4
+
5
+ * Copyright (c) 2013-2014 QBurst Technologies Inc.
6
+
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ * THE SOFTWARE.
24
+
25
+ **************************************************************************
26
+ =end
27
+
28
+ require_relative './helper'
29
+
30
+ $test_file = "dummy"
31
+ $test_file_root = "#{Dir.pwd}/test"
32
+
33
+ class TestViberModulePlugin < Test::Unit::TestCase
34
+
35
+ AUTHENTICATE_MODULE_FILES = ["app/apis/#{$test_file}/modules/authentication_apis.rb"]
36
+ COMMON_FILES = ['db/migrate/01_create_users.rb','db/migrate/02_create_sessions.rb', 'app/models/user.rb',
37
+ 'app/models/session.rb', 'app/models/oauth2_authorization.rb']
38
+ AUTHORIZE_MODULE_FILES = ["app/apis/#{$test_file}/modules/authorization_apis.rb"]
39
+ OAUTH_MODULE_FILES = ["app/apis/#{$test_file}/modules/oauth_apis.rb",'db/migrate/03_create_owners.rb',
40
+ 'db/migrate/04_create_oauth2_authorizations.rb', 'db/migrate/05_create_oauth2_clients.rb',
41
+ 'app/models/oauth2_client.rb', 'app/models/owner.rb']
42
+ MODULE_CLASS = $test_file.split('_').map(&:capitalize)*''
43
+
44
+ def test_generator_root_module_mount_authenticate
45
+ Dir.chdir("#{Dir.pwd}/#{$test_file}")
46
+ dir_path = Dir.pwd
47
+ module_class = "::#{MODULE_CLASS}::AuthenticationApis"
48
+ options = { :project_name => "#{$test_file}", :module_class => module_class,
49
+ :module_name => "authentication", :action => "-p"}
50
+ generator = Rammer::ModuleGenerator.new(options)
51
+ generator.run
52
+ AUTHENTICATE_MODULE_FILES.each do |file|
53
+ assert_equal(true, File.file?("#{dir_path}/#{file}"))
54
+ end
55
+ COMMON_FILES.each do |file|
56
+ assert_equal(true, File.file?("#{dir_path}/#{file}"))
57
+ end
58
+ end
59
+
60
+ def test_generator_root_module_mount_authorize
61
+ dir_path = Dir.pwd
62
+ module_class = "::#{MODULE_CLASS}::AuthorizationApis"
63
+ options = { :project_name => "#{$test_file}", :module_class => module_class,
64
+ :module_name => "authorization", :action => "-p"}
65
+ generator = Rammer::ModuleGenerator.new(options)
66
+ generator.run
67
+ AUTHORIZE_MODULE_FILES.each do |file|
68
+ assert_equal(true, File.file?("#{dir_path}/#{file}"))
69
+ end
70
+ COMMON_FILES.each do |file|
71
+ assert_equal(true, File.file?("#{dir_path}/#{file}"))
72
+ end
73
+ end
74
+
75
+ def test_generator_root_module_mount_oauth
76
+ dir_path = Dir.pwd
77
+ module_class = "::#{MODULE_CLASS}::OauthApis"
78
+ options = { :project_name => "#{$test_file}", :module_class => module_class,
79
+ :module_name => "oauth", :action => "-p"}
80
+ generator = Rammer::ModuleGenerator.new(options)
81
+ generator.run
82
+ OAUTH_MODULE_FILES.each do |file|
83
+ assert_equal(true, File.file?("#{dir_path}/#{file}"))
84
+ end
85
+ COMMON_FILES.each do |file|
86
+ assert_equal(true, File.file?("#{dir_path}/#{file}"))
87
+ end
88
+ end
89
+
90
+ def test_generator_root_mounting_exists
91
+ dir_path = Dir.pwd
92
+ module_class = "::#{MODULE_CLASS}::AuthenticationApis"
93
+ options = { :project_name => "#{$test_file}", :module_class => module_class,
94
+ :module_name => "authentication", :action => "-p"}
95
+ generator = Rammer::ModuleGenerator.new(options)
96
+ generator.run
97
+ AUTHENTICATE_MODULE_FILES.each do |file|
98
+ assert_equal(true, File.file?("#{dir_path}/#{file}"))
99
+ end
100
+ COMMON_FILES.each do |file|
101
+ assert_equal(true, File.file?("#{dir_path}/#{file}"))
102
+ end
103
+ end
104
+ end