melodiest 1.0.0 → 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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +1 -1
- data/Gemfile.lock +1 -25
- data/LICENSE.txt +1 -1
- data/README.md +15 -29
- data/lib/melodiest.rb +1 -17
- data/lib/melodiest/templates/Gemfile.erb +3 -1
- data/lib/melodiest/templates/app.erb +6 -3
- data/lib/melodiest/version.rb +1 -1
- data/melodiest.gemspec +1 -5
- data/spec/fixtures/with_db/app.txt +5 -2
- data/spec/fixtures/with_db/gemfile.txt +3 -1
- data/spec/fixtures/without_db/app.txt +4 -3
- data/spec/fixtures/without_db/gemfile.txt +3 -1
- data/spec/helpers/generator.rb +46 -0
- data/spec/melodiest/command_spec.rb +6 -3
- data/spec/melodiest/generator_spec.rb +41 -114
- data/spec/melodiest_spec.rb +1 -15
- data/spec/spec_helper.rb +0 -63
- metadata +4 -61
- data/lib/melodiest/setting.rb +0 -8
- data/lib/melodiest/templates/public/.DS_Store +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79d0d120efedd4b0f01025a4ce1c98e50af974c5
|
4
|
+
data.tar.gz: 46b4f818997bbbfed1bf3c3b4309ebc6bfeb229e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1203ee900d402a4922792a3edf5a9a771305bc7a2174dd497f7de26be4f6929d8b7cbd9c28657e3bde9c7597feb2c25db73c703b752f2424c3b9003222a907f
|
7
|
+
data.tar.gz: e7ae8844ff29e53e0af62067e625e0e1348e2215ebf2fd3e1c2abe9f2aa842e4dd772fad1fd86822f26b5d9c364b827f97e56eb48a52d20214c859da5c69b30c
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,23 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
melodiest (0.
|
5
|
-
encrypted_cookie (= 0.0.4)
|
6
|
-
sinatra (= 1.4.6)
|
7
|
-
sinatra-contrib (= 1.4.2)
|
4
|
+
melodiest (1.0.0)
|
8
5
|
|
9
6
|
GEM
|
10
7
|
remote: https://rubygems.org/
|
11
8
|
specs:
|
12
|
-
backports (3.6.4)
|
13
9
|
diff-lcs (1.2.5)
|
14
|
-
encrypted_cookie (0.0.4)
|
15
|
-
multi_json (1.11.2)
|
16
|
-
rack (1.6.0)
|
17
|
-
rack-protection (1.5.3)
|
18
|
-
rack
|
19
|
-
rack-test (0.6.3)
|
20
|
-
rack (>= 1.0)
|
21
10
|
rspec (3.2.0)
|
22
11
|
rspec-core (~> 3.2.0)
|
23
12
|
rspec-expectations (~> 3.2.0)
|
@@ -31,18 +20,6 @@ GEM
|
|
31
20
|
diff-lcs (>= 1.2.0, < 2.0)
|
32
21
|
rspec-support (~> 3.2.0)
|
33
22
|
rspec-support (3.2.2)
|
34
|
-
sinatra (1.4.6)
|
35
|
-
rack (~> 1.4)
|
36
|
-
rack-protection (~> 1.4)
|
37
|
-
tilt (>= 1.3, < 3)
|
38
|
-
sinatra-contrib (1.4.2)
|
39
|
-
backports (>= 2.0)
|
40
|
-
multi_json
|
41
|
-
rack-protection
|
42
|
-
rack-test
|
43
|
-
sinatra (~> 1.4.0)
|
44
|
-
tilt (~> 1.3)
|
45
|
-
tilt (1.4.1)
|
46
23
|
|
47
24
|
PLATFORMS
|
48
25
|
ruby
|
@@ -50,5 +27,4 @@ PLATFORMS
|
|
50
27
|
DEPENDENCIES
|
51
28
|
bundler (~> 1.7)
|
52
29
|
melodiest!
|
53
|
-
rack-test (= 0.6.3)
|
54
30
|
rspec (= 3.2.0)
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -35,20 +35,6 @@ generate app in current directory with database. `-d` option will generate app w
|
|
35
35
|
melodiest -n my_app -d
|
36
36
|
```
|
37
37
|
|
38
|
-
### Melodiest::Application
|
39
|
-
Because Melodiest is already required Sinatra, you don't have to require 'sinatra' anymore, just require 'melodiest'.
|
40
|
-
|
41
|
-
`Melodiest::Application` is subclass from `Sinatra::Application`.
|
42
|
-
|
43
|
-
```ruby
|
44
|
-
# my_app.rb
|
45
|
-
|
46
|
-
class App < Melodiest::Application
|
47
|
-
cookie_secret 'this_is_secret_for_encrypted_cookie'
|
48
|
-
...
|
49
|
-
end
|
50
|
-
```
|
51
|
-
|
52
38
|
### Example Usage
|
53
39
|
This example assume that PostgreSQL is already running and desired database is already exist.
|
54
40
|
For complete example see [github.com/kuntoaji/todo_melodiest](https://github.com/kuntoaji/todo_melodiest)
|
@@ -57,7 +43,7 @@ For complete example see [github.com/kuntoaji/todo_melodiest](https://github.com
|
|
57
43
|
3. run `bundle install`
|
58
44
|
4. create `config/database.yml` and configure your database setting
|
59
45
|
5. create file `db/migrations/001_create_artists.rb` and put the following code:
|
60
|
-
|
46
|
+
|
61
47
|
```ruby
|
62
48
|
Sequel.migration do
|
63
49
|
up do
|
@@ -66,42 +52,42 @@ For complete example see [github.com/kuntoaji/todo_melodiest](https://github.com
|
|
66
52
|
String :name, :null=>false
|
67
53
|
end
|
68
54
|
end
|
69
|
-
|
55
|
+
|
70
56
|
down do
|
71
57
|
drop_table(:artists)
|
72
58
|
end
|
73
59
|
end
|
74
60
|
```
|
75
|
-
|
61
|
+
|
76
62
|
6. run `rake db:migrate`
|
77
63
|
7. create file `app/models/Artist.rb` and put the following code:
|
78
|
-
|
64
|
+
|
79
65
|
```ruby
|
80
66
|
class Artist < Sequel::Model
|
81
67
|
end
|
82
68
|
```
|
83
|
-
|
69
|
+
|
84
70
|
8. create file `app/routes/artists.rb` and put the following code:
|
85
|
-
|
71
|
+
|
86
72
|
```ruby
|
87
73
|
class MyApp
|
88
74
|
get '/artists' do
|
89
75
|
@artists = Artist.all
|
90
76
|
erb :"artists/index"
|
91
77
|
end
|
92
|
-
|
78
|
+
|
93
79
|
post '/artists' do
|
94
80
|
@artist = Artist.new
|
95
81
|
@artist.name = params[:name]
|
96
82
|
@artist.save
|
97
|
-
|
83
|
+
|
98
84
|
redirect '/artists'
|
99
85
|
end
|
100
86
|
end
|
101
87
|
```
|
102
|
-
|
88
|
+
|
103
89
|
9. create file `app/views/artists/index.erb` and put the following code:
|
104
|
-
|
90
|
+
|
105
91
|
```erb
|
106
92
|
<h1>List of Artist</h1>
|
107
93
|
<ul>
|
@@ -109,22 +95,22 @@ For complete example see [github.com/kuntoaji/todo_melodiest](https://github.com
|
|
109
95
|
<li><%= artist.name %></li>
|
110
96
|
<% end %>
|
111
97
|
</ul>
|
112
|
-
|
98
|
+
|
113
99
|
<form action="/artists" method="post">
|
114
100
|
<%= Rack::Csrf.tag(env) %>
|
115
101
|
<input type="text" name="name" />
|
116
102
|
<button>Submit</button>
|
117
103
|
</form>
|
118
104
|
```
|
119
|
-
|
105
|
+
|
120
106
|
10. run the server `bundle exec thin start`
|
121
107
|
11. open url `localhost:3000/artists`
|
122
108
|
|
123
109
|
### List of Ruby Gems
|
124
110
|
|
125
|
-
* sinatra
|
126
|
-
* sinatra-contrib
|
127
|
-
* encrypted_cookie
|
111
|
+
* sinatra
|
112
|
+
* sinatra-contrib
|
113
|
+
* encrypted_cookie
|
128
114
|
* `Sinatra::Reloader` in development environment only
|
129
115
|
* thin
|
130
116
|
* `Rack::Session::EncryptedCookie`
|
data/lib/melodiest.rb
CHANGED
@@ -1,17 +1 @@
|
|
1
|
-
|
2
|
-
require 'encrypted_cookie'
|
3
|
-
|
4
|
-
module Melodiest
|
5
|
-
class Application < Sinatra::Application
|
6
|
-
def self.cookie_secret(secret)
|
7
|
-
use Rack::Session::EncryptedCookie,
|
8
|
-
secret: secret
|
9
|
-
end
|
10
|
-
|
11
|
-
# http://www.sinatrarb.com/contrib/reloader.html
|
12
|
-
configure :development do
|
13
|
-
require 'sinatra/reloader'
|
14
|
-
register Sinatra::Reloader
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
1
|
+
# :)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
<%= "require 'yaml'\n\n" if @with_database -%>
|
2
|
-
class <%= @app_class_name %> <
|
3
|
-
|
2
|
+
class <%= @app_class_name %> < Sinatra::Application
|
3
|
+
use Rack::Session::EncryptedCookie,
|
4
|
+
secret: '<%= SecureRandom.hex 32 %>'
|
4
5
|
|
5
6
|
set :app_file, __FILE__
|
6
7
|
set :views, Proc.new { File.join(root, "app/views") }
|
@@ -19,8 +20,10 @@ class <%= @app_class_name %> < Melodiest::Application
|
|
19
20
|
end
|
20
21
|
|
21
22
|
configure :development do
|
23
|
+
require 'sinatra/reloader'
|
22
24
|
require 'logger'
|
23
25
|
|
26
|
+
register Sinatra::Reloader
|
24
27
|
Sequel.connect YAML.load_file(File.expand_path("../config/database.yml", __FILE__))['development'],
|
25
28
|
loggers: [Logger.new($stdout)]
|
26
29
|
end
|
@@ -41,7 +44,7 @@ class <%= @app_class_name %> < Melodiest::Application
|
|
41
44
|
end
|
42
45
|
<% else -%>
|
43
46
|
configure do
|
44
|
-
#
|
47
|
+
# do something
|
45
48
|
end
|
46
49
|
<% end -%>
|
47
50
|
end
|
data/lib/melodiest/version.rb
CHANGED
data/melodiest.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.summary = "Sinatra application boilerplate generator"
|
8
8
|
s.description = "Melodiest provides generator and contains minimal configuration to develop application with Sinatra"
|
9
9
|
s.author = 'Kunto Aji Kristianto'
|
10
|
-
s.email = '
|
10
|
+
s.email = 'kuntoaji@kaklabs.com'
|
11
11
|
s.files = `git ls-files -z`.split("\x0")
|
12
12
|
s.executables << 'melodiest'
|
13
13
|
s.homepage = 'http://github.com/kuntoaji/melodiest'
|
@@ -16,8 +16,4 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.required_ruby_version = '>= 2.1'
|
17
17
|
s.add_development_dependency 'bundler', '~> 1.7'
|
18
18
|
s.add_development_dependency 'rspec', '3.2.0'
|
19
|
-
s.add_development_dependency 'rack-test', '0.6.3'
|
20
|
-
s.add_runtime_dependency 'sinatra', '1.4.6'
|
21
|
-
s.add_runtime_dependency 'sinatra-contrib', '1.4.2'
|
22
|
-
s.add_runtime_dependency 'encrypted_cookie', '0.0.4'
|
23
19
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
|
-
class MyApp <
|
4
|
-
|
3
|
+
class MyApp < Sinatra::Application
|
4
|
+
use Rack::Session::EncryptedCookie,
|
5
|
+
secret: 'supersecretcookiefromgenerator'
|
5
6
|
|
6
7
|
set :app_file, __FILE__
|
7
8
|
set :views, Proc.new { File.join(root, "app/views") }
|
@@ -19,8 +20,10 @@ class MyApp < Melodiest::Application
|
|
19
20
|
end
|
20
21
|
|
21
22
|
configure :development do
|
23
|
+
require 'sinatra/reloader'
|
22
24
|
require 'logger'
|
23
25
|
|
26
|
+
register Sinatra::Reloader
|
24
27
|
Sequel.connect YAML.load_file(File.expand_path("../config/database.yml", __FILE__))['development'],
|
25
28
|
loggers: [Logger.new($stdout)]
|
26
29
|
end
|
@@ -1,5 +1,6 @@
|
|
1
|
-
class MyApp <
|
2
|
-
|
1
|
+
class MyApp < Sinatra::Application
|
2
|
+
use Rack::Session::EncryptedCookie,
|
3
|
+
secret: 'supersecretcookiefromgenerator'
|
3
4
|
|
4
5
|
set :app_file, __FILE__
|
5
6
|
set :views, Proc.new { File.join(root, "app/views") }
|
@@ -10,6 +11,6 @@ class MyApp < Melodiest::Application
|
|
10
11
|
use Rack::Csrf, raise: true
|
11
12
|
|
12
13
|
configure do
|
13
|
-
#
|
14
|
+
# do something
|
14
15
|
end
|
15
16
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Helper
|
2
|
+
module Generator
|
3
|
+
def expect_file_eq(file, expected_file)
|
4
|
+
file_content = File.read(file)
|
5
|
+
expected_file_content = File.read(expected_file)
|
6
|
+
|
7
|
+
expect(File.exists?(file)).to be_truthy
|
8
|
+
expect(file_content).to eq(expected_file_content)
|
9
|
+
end
|
10
|
+
|
11
|
+
def expected_default_files(target_dir, expected_value)
|
12
|
+
config_dir = "#{target_dir}/config"
|
13
|
+
assets_dir = "#{target_dir}/assets"
|
14
|
+
public_dir = "#{target_dir}/public"
|
15
|
+
boot = "#{config_dir}/boot.rb"
|
16
|
+
application = "#{config_dir}/application.rb"
|
17
|
+
|
18
|
+
app_dir = "#{target_dir}/app"
|
19
|
+
routes_dir = "#{target_dir}/app/routes"
|
20
|
+
views_dir = "#{target_dir}/app/views"
|
21
|
+
layout = "#{target_dir}/app/views/layout.erb"
|
22
|
+
home_index = "#{target_dir}/app/views/home/index.erb"
|
23
|
+
|
24
|
+
expect(File.exists?(config_dir)).to eq(expected_value)
|
25
|
+
expect(File.exists?("#{config_dir}/boot.rb")).to eq(expected_value)
|
26
|
+
expect(File.exists?("#{config_dir}/application.rb")).to eq(expected_value)
|
27
|
+
expect(File.exists?(assets_dir)).to eq(expected_value)
|
28
|
+
expect(File.exists?(public_dir)).to eq(expected_value)
|
29
|
+
|
30
|
+
expect(Dir.exists?(app_dir)).to eq(expected_value)
|
31
|
+
expect(Dir.exists?(routes_dir)).to eq(expected_value)
|
32
|
+
expect(Dir.exists?(views_dir)).to eq(expected_value)
|
33
|
+
expect(File.exists?(layout)).to eq(expected_value)
|
34
|
+
expect(File.exists?(home_index)).to eq(expected_value)
|
35
|
+
end
|
36
|
+
|
37
|
+
def expected_generated_files_with_db(target_dir, expected_value)
|
38
|
+
sample_migration = "#{target_dir}/db/migrations/000_example.rb"
|
39
|
+
|
40
|
+
expect(Dir.exists?("#{target_dir}/app/models")).to eq(expected_value)
|
41
|
+
expect(File.exists?("#{target_dir}/config/database.yml.example")).to eq(expected_value)
|
42
|
+
expect(File.exists?(sample_migration)).to eq(expected_value)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -3,14 +3,17 @@ require_relative '../../lib/melodiest/command'
|
|
3
3
|
describe Melodiest::Command do
|
4
4
|
|
5
5
|
describe "parse" do
|
6
|
-
|
6
|
+
def remove_existing_app_if_exists
|
7
7
|
FileUtils.rm_r "my_app" if Dir.exists?("my_app")
|
8
8
|
FileUtils.rm_r "/tmp/my_app" if Dir.exists?("/tmp/my_app")
|
9
9
|
end
|
10
10
|
|
11
|
+
before do
|
12
|
+
remove_existing_app_if_exists
|
13
|
+
end
|
14
|
+
|
11
15
|
after :all do
|
12
|
-
|
13
|
-
FileUtils.rm_r "/tmp/my_app" if Dir.exists?("/tmp/my_app")
|
16
|
+
remove_existing_app_if_exists
|
14
17
|
end
|
15
18
|
|
16
19
|
it "has --help option" do
|
@@ -1,25 +1,26 @@
|
|
1
1
|
require_relative '../../lib/melodiest/generator'
|
2
|
+
require_relative '../helpers/generator'
|
2
3
|
|
3
4
|
describe Melodiest::Generator do
|
5
|
+
include Helper::Generator
|
6
|
+
|
4
7
|
let(:generator) { Melodiest::Generator.new @app, destination: @dest }
|
5
8
|
let(:generator_with_db) { Melodiest::Generator.new @app, destination: @dest_with_db, with_database: true }
|
6
9
|
let(:target_dir) { "#{@dest}/#{@app}" }
|
7
10
|
let(:target_dir_with_db) { "#{@dest_with_db}/#{@app}" }
|
8
11
|
|
9
|
-
before
|
12
|
+
before do
|
10
13
|
@dest = "/tmp/melodiest"
|
11
14
|
@dest_with_db = "#{@dest}_with_db"
|
12
15
|
@app = "my_app"
|
13
|
-
end
|
14
16
|
|
15
|
-
before :all do
|
16
17
|
FileUtils.rm_r @dest if Dir.exists?(@dest)
|
17
18
|
FileUtils.rm_r @dest_with_db if Dir.exists?(@dest_with_db)
|
18
19
|
end
|
19
20
|
|
20
|
-
after
|
21
|
-
FileUtils.rm_r @dest
|
22
|
-
FileUtils.rm_r @dest_with_db
|
21
|
+
after do
|
22
|
+
FileUtils.rm_r @dest if Dir.exists?(@dest)
|
23
|
+
FileUtils.rm_r @dest_with_db if Dir.exists?(@dest_with_db)
|
23
24
|
end
|
24
25
|
|
25
26
|
it "sets app_name" do
|
@@ -33,105 +34,68 @@ describe Melodiest::Generator do
|
|
33
34
|
it "has default destination path app_name" do
|
34
35
|
FileUtils.rm_r @app if Dir.exists?(@app)
|
35
36
|
expect(Melodiest::Generator.new(@app).destination).to eq File.expand_path(@app)
|
36
|
-
FileUtils.rm_r @app
|
37
|
+
FileUtils.rm_r @app if Dir.exists?(@app)
|
37
38
|
end
|
38
39
|
|
39
40
|
it "sets new destination path even if it's not exist yet" do
|
40
|
-
expect(
|
41
|
+
expect(Melodiest::Generator.new(@dest).destination).to eq File.expand_path(@dest)
|
41
42
|
end
|
42
43
|
|
43
44
|
describe "#generate_gemfile" do
|
44
45
|
context "without database" do
|
45
46
|
let(:gemfile) { "#{target_dir}/Gemfile" }
|
47
|
+
let(:expected_gemfile) { File.expand_path("../../fixtures/without_db/gemfile.txt", __FILE__) }
|
46
48
|
|
47
49
|
it "should generate Gemfile without sequel" do
|
48
50
|
generator.generate_gemfile
|
49
|
-
|
50
|
-
expected_file_content = File.read(File.expand_path("../../fixtures/without_db/gemfile.txt", __FILE__))
|
51
|
-
|
52
|
-
expect(File.exists?(gemfile)).to be_truthy
|
53
|
-
expect(file_content).to eq(expected_file_content)
|
51
|
+
expect_file_eq(gemfile, expected_gemfile)
|
54
52
|
end
|
55
53
|
end
|
56
54
|
|
57
55
|
context "with database" do
|
58
56
|
let(:gemfile) { "#{target_dir_with_db}/Gemfile" }
|
57
|
+
let(:expected_gemfile) { File.expand_path("../../fixtures/with_db/gemfile.txt", __FILE__) }
|
59
58
|
|
60
59
|
it "should generate Gemfile with sequel" do
|
61
60
|
generator_with_db.generate_gemfile
|
62
|
-
|
63
|
-
expected_file_content = File.read(File.expand_path("../../fixtures/with_db/gemfile.txt", __FILE__))
|
64
|
-
|
65
|
-
expect(File.exists?(gemfile)).to be_truthy
|
66
|
-
expect(file_content).to eq(expected_file_content)
|
61
|
+
expect_file_eq(gemfile, expected_gemfile)
|
67
62
|
end
|
68
63
|
end
|
69
64
|
end
|
70
65
|
|
71
66
|
describe "#generate_bundle_config" do
|
72
67
|
let(:bundle_config) { "#{target_dir}/config.ru" }
|
68
|
+
let(:expected_bundle_config) { File.expand_path("../../fixtures/config_ru.txt", __FILE__) }
|
73
69
|
|
74
70
|
it "should generate config.ru with correct content" do
|
75
71
|
generator.generate_bundle_config
|
76
|
-
|
77
|
-
expected_file_content = File.read(File.expand_path("../../fixtures/config_ru.txt", __FILE__))
|
78
|
-
|
79
|
-
expect(File.exists?(bundle_config)).to be_truthy
|
80
|
-
expect(file_content).to eq(expected_file_content)
|
72
|
+
expect_file_eq(bundle_config, expected_bundle_config)
|
81
73
|
end
|
82
74
|
end
|
83
75
|
|
84
76
|
describe "#generate_app" do
|
85
|
-
before { FileUtils.rm_r @dest if Dir.exists?(@dest) }
|
86
|
-
before { FileUtils.rm_r @dest_with_db if Dir.exists?(@dest_with_db) }
|
87
|
-
|
88
77
|
it "generates home route" do
|
89
78
|
generator.generate_app
|
90
79
|
|
91
|
-
app_file = "#{target_dir}/app/routes/home.rb"
|
92
80
|
erb_file = "#{target_dir}/app/routes/home.erb"
|
93
|
-
|
94
|
-
|
81
|
+
generated_file = "#{target_dir}/app/routes/home.rb"
|
82
|
+
expected_file = File.expand_path("../../fixtures/app_routes_home.txt", __FILE__)
|
95
83
|
|
96
|
-
expect(File.exists?(app_file)).to be_truthy
|
97
84
|
expect(File.exists?(erb_file)).to be_falsey
|
98
|
-
expect(
|
85
|
+
expect(File.exists?(generated_file)).to be_truthy
|
86
|
+
expect_file_eq(generated_file, expected_file)
|
99
87
|
end
|
100
88
|
|
101
89
|
context "when generating without database" do
|
102
90
|
describe "copy_templates" do
|
103
|
-
let(:config_dir) { "#{target_dir}/config" }
|
104
|
-
let(:assets_dir) { "#{target_dir}/assets" }
|
105
|
-
let(:public_dir) { "#{target_dir}/public" }
|
106
|
-
let(:without_db_sample_migration) { "#{target_dir}/db_migrations/000_example.rb" }
|
107
|
-
|
108
91
|
it "copies from melodiest templates" do
|
109
|
-
|
110
|
-
|
111
|
-
expect(File.exists?(assets_dir)).to be_falsey
|
112
|
-
expect(File.exists?(public_dir)).to be_falsey
|
113
|
-
|
114
|
-
expect(Dir.exists?("#{target_dir}/app")).to be_falsey
|
115
|
-
expect(Dir.exists?("#{target_dir}/app/routes")).to be_falsey
|
116
|
-
expect(Dir.exists?("#{target_dir}/app/models")).to be_falsey
|
117
|
-
expect(Dir.exists?("#{target_dir}/app/views")).to be_falsey
|
118
|
-
expect(File.exists?("#{target_dir}/app/views/layout.erb")).to be_falsey
|
119
|
-
expect(File.exists?("#{target_dir}/app/views/home/index.erb")).to be_falsey
|
92
|
+
expected_default_files(target_dir, false)
|
93
|
+
expected_generated_files_with_db(target_dir, false)
|
120
94
|
|
121
95
|
generator.generate_app
|
122
96
|
|
123
|
-
|
124
|
-
|
125
|
-
expect(File.exists?(without_db_sample_migration)).to be_falsey
|
126
|
-
expect(File.exists?(assets_dir)).to be_truthy
|
127
|
-
expect(File.exists?(public_dir)).to be_truthy
|
128
|
-
|
129
|
-
expect(Dir.exists?("#{target_dir}/app")).to be_truthy
|
130
|
-
expect(Dir.exists?("#{target_dir}/app/routes")).to be_truthy
|
131
|
-
expect(Dir.exists?("#{target_dir}/app/models")).to be_falsey
|
132
|
-
expect(Dir.exists?("#{target_dir}/app/views")).to be_truthy
|
133
|
-
expect(File.exists?("#{target_dir}/app/views/layout.erb")).to be_truthy
|
134
|
-
expect(File.exists?("#{target_dir}/app/views/home/index.erb")).to be_truthy
|
97
|
+
expected_default_files(target_dir, true)
|
98
|
+
expected_generated_files_with_db(target_dir, false)
|
135
99
|
end
|
136
100
|
end
|
137
101
|
|
@@ -142,57 +106,24 @@ describe Melodiest::Generator do
|
|
142
106
|
it "generates <app_name>.rb, public dir, and app dir" do
|
143
107
|
generator.generate_app
|
144
108
|
|
145
|
-
|
146
|
-
|
147
|
-
expected_file_content = File.read(File.expand_path("../../fixtures/without_db/app.txt", __FILE__))
|
109
|
+
generated_file = "#{target_dir}/my_app.rb"
|
110
|
+
expected_file = File.expand_path("../../fixtures/without_db/app.txt", __FILE__)
|
148
111
|
|
149
|
-
|
150
|
-
expect(file_content).to eq expected_file_content
|
112
|
+
expect_file_eq(generated_file, expected_file)
|
151
113
|
end
|
152
114
|
end
|
153
115
|
end
|
154
116
|
|
155
117
|
context "when generating with database" do
|
156
118
|
describe "copy templates" do
|
157
|
-
let(:config_dir) { "#{target_dir_with_db}/config" }
|
158
|
-
let(:assets_dir) { "#{target_dir_with_db}/assets" }
|
159
|
-
let(:public_dir) { "#{target_dir_with_db}/public" }
|
160
|
-
let(:with_db_sample_migration) { "#{target_dir_with_db}/db/migrations/000_example.rb" }
|
161
|
-
|
162
119
|
it "copies from melodiest templates" do
|
163
|
-
|
164
|
-
|
165
|
-
expect(File.exists?("#{config_dir}/boot.rb")).to be_falsey
|
166
|
-
expect(File.exists?("#{config_dir}/application.rb")).to be_falsey
|
167
|
-
|
168
|
-
expect(File.exists?(with_db_sample_migration)).to be_falsey
|
169
|
-
expect(File.exists?(assets_dir)).to be_falsey
|
170
|
-
expect(File.exists?(public_dir)).to be_falsey
|
171
|
-
|
172
|
-
expect(Dir.exists?("#{target_dir_with_db}/app")).to be_falsey
|
173
|
-
expect(Dir.exists?("#{target_dir_with_db}/app/routes")).to be_falsey
|
174
|
-
expect(Dir.exists?("#{target_dir_with_db}/app/models")).to be_falsey
|
175
|
-
expect(Dir.exists?("#{target_dir_with_db}/app/views")).to be_falsey
|
176
|
-
expect(File.exists?("#{target_dir_with_db}/app/views/layout.erb")).to be_falsey
|
177
|
-
expect(File.exists?("#{target_dir_with_db}/app/views/home/index.erb")).to be_falsey
|
120
|
+
expected_default_files(target_dir_with_db, false)
|
121
|
+
expected_generated_files_with_db(target_dir_with_db, false)
|
178
122
|
|
179
123
|
generator_with_db.generate_app
|
180
124
|
|
181
|
-
|
182
|
-
|
183
|
-
expect(File.exists?("#{config_dir}/boot.rb")).to be_truthy
|
184
|
-
expect(File.exists?("#{config_dir}/application.rb")).to be_truthy
|
185
|
-
|
186
|
-
expect(File.exists?(with_db_sample_migration)).to be_truthy
|
187
|
-
expect(File.exists?(assets_dir)).to be_truthy
|
188
|
-
expect(File.exists?(public_dir)).to be_truthy
|
189
|
-
|
190
|
-
expect(Dir.exists?("#{target_dir_with_db}/app")).to be_truthy
|
191
|
-
expect(Dir.exists?("#{target_dir_with_db}/app/routes")).to be_truthy
|
192
|
-
expect(Dir.exists?("#{target_dir_with_db}/app/models")).to be_truthy
|
193
|
-
expect(Dir.exists?("#{target_dir_with_db}/app/views")).to be_truthy
|
194
|
-
expect(File.exists?("#{target_dir_with_db}/app/views/layout.erb")).to be_truthy
|
195
|
-
expect(File.exists?("#{target_dir_with_db}/app/views/home/index.erb")).to be_truthy
|
125
|
+
expected_default_files(target_dir_with_db, true)
|
126
|
+
expected_generated_files_with_db(target_dir_with_db, true)
|
196
127
|
end
|
197
128
|
end
|
198
129
|
|
@@ -203,11 +134,10 @@ describe Melodiest::Generator do
|
|
203
134
|
it "has sequel database connector" do
|
204
135
|
generator_with_db.generate_app
|
205
136
|
|
206
|
-
|
207
|
-
|
208
|
-
expected_file_content = File.read(File.expand_path("../../fixtures/with_db/app.txt", __FILE__))
|
137
|
+
generated_file = "#{target_dir_with_db}/my_app.rb"
|
138
|
+
expected_file = File.expand_path("../../fixtures/with_db/app.txt", __FILE__)
|
209
139
|
|
210
|
-
|
140
|
+
expect_file_eq(generated_file, expected_file)
|
211
141
|
end
|
212
142
|
end
|
213
143
|
end
|
@@ -215,25 +145,22 @@ describe Melodiest::Generator do
|
|
215
145
|
|
216
146
|
describe "#generate_rakefile" do
|
217
147
|
it "generate basic Rakefile tasks" do
|
218
|
-
expected_rakefile_content =
|
219
|
-
expected_rakefile_content = File.read(File.expand_path("../../fixtures/without_db/rakefile.txt", __FILE__))
|
220
|
-
|
221
148
|
generator.generate_rakefile
|
222
|
-
rakefile = "#{target_dir}/Rakefile"
|
223
|
-
rakefile_content = File.read(rakefile)
|
224
149
|
|
225
|
-
|
150
|
+
generated_file = "#{target_dir}/Rakefile"
|
151
|
+
expected_file = File.expand_path("../../fixtures/without_db/rakefile.txt", __FILE__)
|
152
|
+
|
153
|
+
expect_file_eq(generated_file, expected_file)
|
226
154
|
end
|
227
155
|
|
228
156
|
context "with database" do
|
229
157
|
it "generates db related tasks" do
|
230
|
-
expected_rakefile_content = File.read(File.expand_path("../../fixtures/with_db/rakefile.txt", __FILE__))
|
231
|
-
|
232
158
|
generator_with_db.generate_rakefile
|
233
|
-
rakefile = "#{target_dir_with_db}/Rakefile"
|
234
|
-
rakefile_content = File.read(rakefile)
|
235
159
|
|
236
|
-
|
160
|
+
generated_file = "#{target_dir_with_db}/Rakefile"
|
161
|
+
expected_file = File.expand_path("../../fixtures/with_db/rakefile.txt", __FILE__)
|
162
|
+
|
163
|
+
expect_file_eq(generated_file, expected_file)
|
237
164
|
end
|
238
165
|
end
|
239
166
|
end
|
data/spec/melodiest_spec.rb
CHANGED
@@ -1,15 +1 @@
|
|
1
|
-
|
2
|
-
let(:my_app) do
|
3
|
-
class MyApp < Melodiest::Application
|
4
|
-
cookie_secret 'mysupersecretcookie'
|
5
|
-
end
|
6
|
-
|
7
|
-
MyApp
|
8
|
-
end
|
9
|
-
|
10
|
-
|
11
|
-
it "use encrypted cookie" do
|
12
|
-
expect(my_app.instance_variable_get("@middleware")).to include
|
13
|
-
[Rack::Session::EncryptedCookie, [{:secret => "mysupersecretcookie"}], nil]
|
14
|
-
end
|
15
|
-
end
|
1
|
+
# :)
|
data/spec/spec_helper.rb
CHANGED
@@ -1,92 +1,29 @@
|
|
1
1
|
ENV['RACK_ENV'] = 'test'
|
2
|
-
require 'rack/test'
|
3
2
|
require_relative '../lib/melodiest'
|
4
3
|
|
5
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
6
4
|
RSpec.configure do |config|
|
7
|
-
config.include Rack::Test::Methods
|
8
|
-
|
9
|
-
# rspec-expectations config goes here. You can use an alternate
|
10
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
11
|
-
# assertions if you prefer.
|
12
5
|
config.expect_with :rspec do |expectations|
|
13
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
14
|
-
# and `failure_message` of custom matchers include text for helper methods
|
15
|
-
# defined using `chain`, e.g.:
|
16
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
17
|
-
# # => "be bigger than 2 and smaller than 4"
|
18
|
-
# ...rather than:
|
19
|
-
# # => "be bigger than 2"
|
20
6
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
21
7
|
end
|
22
8
|
|
23
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
24
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
25
9
|
config.mock_with :rspec do |mocks|
|
26
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
27
|
-
# a real object. This is generally recommended, and will default to
|
28
|
-
# `true` in RSpec 4.
|
29
10
|
mocks.verify_partial_doubles = true
|
30
11
|
end
|
31
12
|
|
32
13
|
begin
|
33
|
-
# These two settings work together to allow you to limit a spec run
|
34
|
-
# to individual examples or groups you care about by tagging them with
|
35
|
-
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
36
|
-
# get run.
|
37
14
|
config.filter_run :focus
|
38
15
|
config.run_all_when_everything_filtered = true
|
39
16
|
|
40
|
-
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
41
|
-
# For more details, see:
|
42
|
-
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
43
|
-
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
44
|
-
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
45
17
|
#config.disable_monkey_patching!
|
46
|
-
|
47
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
48
|
-
# be too noisy due to issues in dependencies.
|
49
|
-
#config.warnings = true
|
50
18
|
config.warnings = false
|
51
19
|
|
52
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
53
|
-
# file, and it's useful to allow more verbose output when running an
|
54
|
-
# individual spec file.
|
55
20
|
if config.files_to_run.one?
|
56
|
-
# Use the documentation formatter for detailed output,
|
57
|
-
# unless a formatter has already been configured
|
58
|
-
# (e.g. via a command-line flag).
|
59
21
|
config.default_formatter = 'doc'
|
60
22
|
end
|
61
23
|
|
62
|
-
# Print the 10 slowest examples and example groups at the
|
63
|
-
# end of the spec run, to help surface which specs are running
|
64
|
-
# particularly slow.
|
65
24
|
config.profile_examples = 10
|
66
|
-
|
67
|
-
# Run specs in random order to surface order dependencies. If you find an
|
68
|
-
# order dependency and want to debug it, you can fix the order by providing
|
69
|
-
# the seed, which is printed after each run.
|
70
|
-
# --seed 1234
|
71
25
|
config.order = :random
|
72
26
|
|
73
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
74
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
75
|
-
# test failures related to randomization by passing the same `--seed` value
|
76
|
-
# as the one that triggered the failure.
|
77
27
|
Kernel.srand config.seed
|
78
28
|
end
|
79
29
|
end
|
80
|
-
|
81
|
-
class SpecApp < Melodiest::Application
|
82
|
-
cookie_secret 'supersecretcookiespec'
|
83
|
-
end
|
84
|
-
|
85
|
-
def app
|
86
|
-
SpecApp
|
87
|
-
end
|
88
|
-
|
89
|
-
def gem_root_path
|
90
|
-
File.expand_path "../../", __FILE__
|
91
|
-
end
|
92
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: melodiest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kunto Aji Kristianto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,65 +38,9 @@ dependencies:
|
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.2.0
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rack-test
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.6.3
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.6.3
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: sinatra
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - '='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 1.4.6
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 1.4.6
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: sinatra-contrib
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - '='
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 1.4.2
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - '='
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 1.4.2
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: encrypted_cookie
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - '='
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.0.4
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - '='
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.0.4
|
97
41
|
description: Melodiest provides generator and contains minimal configuration to develop
|
98
42
|
application with Sinatra
|
99
|
-
email:
|
43
|
+
email: kuntoaji@kaklabs.com
|
100
44
|
executables:
|
101
45
|
- melodiest
|
102
46
|
extensions: []
|
@@ -113,7 +57,6 @@ files:
|
|
113
57
|
- lib/melodiest.rb
|
114
58
|
- lib/melodiest/command.rb
|
115
59
|
- lib/melodiest/generator.rb
|
116
|
-
- lib/melodiest/setting.rb
|
117
60
|
- lib/melodiest/templates/Gemfile.erb
|
118
61
|
- lib/melodiest/templates/Rakefile.erb
|
119
62
|
- lib/melodiest/templates/app.erb
|
@@ -130,7 +73,6 @@ files:
|
|
130
73
|
- lib/melodiest/templates/config/boot.rb
|
131
74
|
- lib/melodiest/templates/config/database.yml.example
|
132
75
|
- lib/melodiest/templates/db/migrations/000_example.rb
|
133
|
-
- lib/melodiest/templates/public/.DS_Store
|
134
76
|
- lib/melodiest/templates/public/404.html
|
135
77
|
- lib/melodiest/templates/public/apple-touch-icon.png
|
136
78
|
- lib/melodiest/templates/public/browserconfig.xml
|
@@ -150,6 +92,7 @@ files:
|
|
150
92
|
- spec/fixtures/without_db/app.txt
|
151
93
|
- spec/fixtures/without_db/gemfile.txt
|
152
94
|
- spec/fixtures/without_db/rakefile.txt
|
95
|
+
- spec/helpers/generator.rb
|
153
96
|
- spec/melodiest/command_spec.rb
|
154
97
|
- spec/melodiest/generator_spec.rb
|
155
98
|
- spec/melodiest_spec.rb
|
data/lib/melodiest/setting.rb
DELETED
Binary file
|