hobby-signup 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +91 -0
- data/hobby-signup.gemspec +10 -0
- data/lib/hobby/signup.rb +32 -0
- data/lib/hobby/template.slim +15 -0
- data/spec/main_spec.rb +62 -0
- data/spec/test_app/app.rb +13 -0
- data/spec/test_app/user.rb +17 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5cbf9e2e97a22780fc0fbf95adb66ef97a3040d48adea0d2dbda6116d1c03c6b
|
4
|
+
data.tar.gz: 483533c5b3824c0c18b181f3585b6bc13f34b529f9755b5bc59983aadd4daf39
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 478b58a075e4f92c9bb16e14fa3209a15c7c59f45f09c6c2c73231135d47639948fb740b2b94024726d7b8041566538d0fb847ca268b61c450d469860d5a9480
|
7
|
+
data.tar.gz: 305a68eebcfa2081451b13c5a9187882b663cc725b030bffdc17dd48bdf41964990da3a2d5dde9d2af3ca4c6d6eb895feb8be70f5248ba40c3e65e32d7b5cdc6
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hobby-signup (0.0.0)
|
5
|
+
hobby
|
6
|
+
slim
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (5.1.5)
|
12
|
+
activesupport (= 5.1.5)
|
13
|
+
activerecord (5.1.5)
|
14
|
+
activemodel (= 5.1.5)
|
15
|
+
activesupport (= 5.1.5)
|
16
|
+
arel (~> 8.0)
|
17
|
+
activesupport (5.1.5)
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
+
i18n (~> 0.7)
|
20
|
+
minitest (~> 5.1)
|
21
|
+
tzinfo (~> 1.1)
|
22
|
+
arel (8.0.0)
|
23
|
+
awesome_print (1.8.0)
|
24
|
+
bcrypt (3.1.11)
|
25
|
+
childprocess (0.8.0)
|
26
|
+
ffi (~> 1.0, >= 1.0.11)
|
27
|
+
coderay (1.1.2)
|
28
|
+
concurrent-ruby (1.0.5)
|
29
|
+
diff-lcs (1.3)
|
30
|
+
ffi (1.9.23)
|
31
|
+
hobby (0.1.2)
|
32
|
+
rack
|
33
|
+
i18n (0.9.5)
|
34
|
+
concurrent-ruby (~> 1.0)
|
35
|
+
method_source (0.9.0)
|
36
|
+
minitest (5.11.3)
|
37
|
+
power_assert (1.1.1)
|
38
|
+
pry (0.11.3)
|
39
|
+
coderay (~> 1.1.0)
|
40
|
+
method_source (~> 0.9.0)
|
41
|
+
puma (3.11.2)
|
42
|
+
rack (2.0.4)
|
43
|
+
rspec (3.7.0)
|
44
|
+
rspec-core (~> 3.7.0)
|
45
|
+
rspec-expectations (~> 3.7.0)
|
46
|
+
rspec-mocks (~> 3.7.0)
|
47
|
+
rspec-core (3.7.1)
|
48
|
+
rspec-support (~> 3.7.0)
|
49
|
+
rspec-expectations (3.7.0)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.7.0)
|
52
|
+
rspec-mocks (3.7.0)
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
+
rspec-support (~> 3.7.0)
|
55
|
+
rspec-power_assert (1.1.0)
|
56
|
+
power_assert (~> 1.1.0)
|
57
|
+
rspec (>= 2.14)
|
58
|
+
rspec-support (3.7.1)
|
59
|
+
rubyzip (1.2.1)
|
60
|
+
selenium-webdriver (3.9.0)
|
61
|
+
childprocess (~> 0.5)
|
62
|
+
rubyzip (~> 1.2)
|
63
|
+
slim (3.0.9)
|
64
|
+
temple (>= 0.7.6, < 0.9)
|
65
|
+
tilt (>= 1.3.3, < 2.1)
|
66
|
+
sqlite3 (1.3.13)
|
67
|
+
temple (0.8.0)
|
68
|
+
thread_safe (0.3.6)
|
69
|
+
tilt (2.0.8)
|
70
|
+
tzinfo (1.2.5)
|
71
|
+
thread_safe (~> 0.1)
|
72
|
+
watir (6.10.3)
|
73
|
+
selenium-webdriver (~> 3.4, >= 3.4.1)
|
74
|
+
|
75
|
+
PLATFORMS
|
76
|
+
ruby
|
77
|
+
|
78
|
+
DEPENDENCIES
|
79
|
+
activerecord
|
80
|
+
awesome_print
|
81
|
+
bcrypt
|
82
|
+
hobby-signup!
|
83
|
+
pry
|
84
|
+
puma
|
85
|
+
rspec
|
86
|
+
rspec-power_assert
|
87
|
+
sqlite3
|
88
|
+
watir
|
89
|
+
|
90
|
+
BUNDLED WITH
|
91
|
+
1.16.1
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Gem::Specification.new do |g|
|
2
|
+
g.name = 'hobby-signup'
|
3
|
+
g.files = `git ls-files`.split($/)
|
4
|
+
g.version = '0.0.0'
|
5
|
+
g.summary = 'A Rack application for signing up.'
|
6
|
+
g.authors = ['Anatoly Chernow']
|
7
|
+
|
8
|
+
g.add_dependency 'hobby'
|
9
|
+
g.add_dependency 'slim'
|
10
|
+
end
|
data/lib/hobby/signup.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'hobby'
|
2
|
+
require 'slim'
|
3
|
+
|
4
|
+
module Hobby
|
5
|
+
class Signup
|
6
|
+
include Hobby
|
7
|
+
|
8
|
+
use Rack::ContentType, 'text/html'
|
9
|
+
|
10
|
+
def initialize model, template = Slim::Template.new("#{__dir__}/template.slim")
|
11
|
+
@model, @template = model, template
|
12
|
+
end
|
13
|
+
|
14
|
+
get {
|
15
|
+
@template.render self
|
16
|
+
}
|
17
|
+
|
18
|
+
post {
|
19
|
+
@user = @model.new request.params
|
20
|
+
@user.save ? success : failure
|
21
|
+
}
|
22
|
+
|
23
|
+
def success
|
24
|
+
response.redirect '/signin'
|
25
|
+
end
|
26
|
+
|
27
|
+
def failure
|
28
|
+
@errors = @user.errors.to_a
|
29
|
+
@template.render self
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
doctype 5
|
2
|
+
html
|
3
|
+
head
|
4
|
+
title Sign up
|
5
|
+
body
|
6
|
+
form(action=script_name method='post')
|
7
|
+
input(type='email' placeholder='Name' name='email' required)
|
8
|
+
input(type='password' placeholder='Password' name='password' required)
|
9
|
+
input(type='password' placeholder='Password Confirmation' name='password_confirmation' required)
|
10
|
+
button(type='submit') Submit
|
11
|
+
|
12
|
+
- if @errors
|
13
|
+
ul
|
14
|
+
- for error in @errors
|
15
|
+
li= error
|
data/spec/main_spec.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative 'test_app/app'
|
2
|
+
|
3
|
+
require 'puma'
|
4
|
+
require 'watir'
|
5
|
+
|
6
|
+
require 'rspec/power_assert'
|
7
|
+
RSpec::PowerAssert.example_assertion_alias :assert
|
8
|
+
RSpec::PowerAssert.example_group_assertion_alias :assert
|
9
|
+
|
10
|
+
class Signup
|
11
|
+
def initialize
|
12
|
+
@browser = Watir::Browser.new
|
13
|
+
@browser.goto '127.0.0.1:8080/signup'
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_accessor :browser
|
17
|
+
attr_accessor :email, :password, :password_confirmation
|
18
|
+
|
19
|
+
def submit
|
20
|
+
form = @browser.form
|
21
|
+
form.text_field(name: 'email').set @name
|
22
|
+
form.text_field(name: 'password').set @password
|
23
|
+
form.text_field(name: 'password_confirmation').set @password_confirmation
|
24
|
+
form.submit
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe do
|
29
|
+
before do
|
30
|
+
@pid = fork do
|
31
|
+
server = Puma::Server.new App.new
|
32
|
+
server.add_tcp_listener '127.0.0.1', 8080
|
33
|
+
server.run
|
34
|
+
sleep
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when it succeeds' do
|
39
|
+
it "redirects to '/signin'" do
|
40
|
+
signup = Signup.new
|
41
|
+
signup.email, signup.password, signup.password_confirmation = 'a', '123', '123'
|
42
|
+
signup.submit
|
43
|
+
|
44
|
+
assert { signup.browser.text.include? 'Sign in.' }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when it fails' do
|
49
|
+
it 'stays on the same page and shows the errors' do
|
50
|
+
signup = Signup.new
|
51
|
+
signup.email, signup.password, signup.password_confirmation = 'a', '123', '1234'
|
52
|
+
signup.submit
|
53
|
+
|
54
|
+
assert { signup.browser.url == 'http://127.0.0.1:8080/signup' }
|
55
|
+
assert { signup.browser.text.include? "Password confirmation doesn't match Password" }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
after do
|
60
|
+
`kill -9 #{@pid}`
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
5
|
+
ActiveRecord::Base.establish_connection adapter: 'sqlite3',
|
6
|
+
database: "/tmp/#{$$}.sqlite"
|
7
|
+
|
8
|
+
ActiveRecord::Schema.define do
|
9
|
+
create_table :users, force: true do |t|
|
10
|
+
t.string :email, null: false
|
11
|
+
t.string :password_digest, null: false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class User < ActiveRecord::Base
|
16
|
+
has_secure_password
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hobby-signup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anatoly Chernow
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hobby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: slim
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- Gemfile
|
48
|
+
- Gemfile.lock
|
49
|
+
- hobby-signup.gemspec
|
50
|
+
- lib/hobby/signup.rb
|
51
|
+
- lib/hobby/template.slim
|
52
|
+
- spec/main_spec.rb
|
53
|
+
- spec/test_app/app.rb
|
54
|
+
- spec/test_app/user.rb
|
55
|
+
homepage:
|
56
|
+
licenses: []
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.7.6
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: A Rack application for signing up.
|
78
|
+
test_files: []
|