bread 0.0.7 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/lib/bread/helper.rb +1 -1
- data/lib/bread/manager/actions.rb +2 -2
- data/lib/bread/manager/actions/controller_scope.rb +5 -5
- data/lib/bread/manager/actions/top_scope.rb +5 -4
- data/lib/bread/version.rb +1 -1
- data/test/dummy/app/controllers/product_photos_controller.rb +12 -16
- data/test/dummy/app/controllers/products_controller.rb +11 -7
- data/test/dummy/app/lib/bread/actions.rb +14 -0
- data/test/dummy/app/lib/bread/crumbs.rb +7 -0
- data/test/dummy/app/views/layouts/application.html.erb +7 -0
- data/test/dummy/app/views/product_photos/_form.html.erb +0 -4
- data/test/dummy/config/environments/test.rb +1 -0
- data/test/dummy/lib/templates/rails/scaffold_controller/controller.rb +146 -0
- data/test/dummy/test/bread_test.rb +0 -1
- data/test/dummy/test/integration/devise_test.rb +166 -0
- data/test/dummy/test/integration/navigation_test.rb +4 -4
- data/test/dummy/test/support/asserts.rb +23 -2
- data/test/dummy/test/support/others.rb +20 -0
- data/test/test_helper.rb +6 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 219fdb18666c32fd524afd1f7f06818a09bfffcd
|
4
|
+
data.tar.gz: 6c99b288b1c8bf890f43a4129f95b9aa9de4b131
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26540026641574a3779a9f000d0c23b0e3ccb2d4af024bafe6c705b507231c3e3a72181b4181e942a4f236e487c1b861ead0a7dfb2d86d5a19b2cdfcc8e093e8
|
7
|
+
data.tar.gz: d4a0b2ae1a881490e97db24889fe4372991df33089e0f639e5d7d6b2aa2de4f98c772673768595b371939effd1515c2e180aa15b073b6118d99c02107422a285
|
data/Gemfile
CHANGED
data/lib/bread/helper.rb
CHANGED
@@ -7,9 +7,9 @@ module Bread
|
|
7
7
|
@top_scope.instance_eval(&block)
|
8
8
|
end
|
9
9
|
|
10
|
-
def get_crumbset(
|
10
|
+
def get_crumbset(controller_path, action_name)
|
11
11
|
reload
|
12
|
-
@top_scope.get_controller_scope(
|
12
|
+
@top_scope.get_controller_scope(controller_path).get_crumbset(action_name)
|
13
13
|
end
|
14
14
|
|
15
15
|
|
@@ -5,9 +5,9 @@ module Bread
|
|
5
5
|
|
6
6
|
attr_reader :top_scope, :parent_crumbs
|
7
7
|
|
8
|
-
def initialize(top_scope,
|
8
|
+
def initialize(top_scope, controller_path, options)
|
9
9
|
@top_scope = top_scope
|
10
|
-
@
|
10
|
+
@controller_path = controller_path
|
11
11
|
@action_scopes = {}
|
12
12
|
@aliases = {}
|
13
13
|
@options = options
|
@@ -24,7 +24,7 @@ module Bread
|
|
24
24
|
|
25
25
|
def get_crumbset(action_name)
|
26
26
|
action_name = get_aliased_action_name(action_name)
|
27
|
-
action_scope = @action_scopes[action_name] || raise("no action scope for '#{action_name}'")
|
27
|
+
action_scope = @action_scopes[action_name] || raise("no action scope for #{@controller_path}#'#{action_name}'")
|
28
28
|
action_scope.crumbset
|
29
29
|
end
|
30
30
|
|
@@ -56,12 +56,12 @@ module Bread
|
|
56
56
|
|
57
57
|
def define_parent_crumbs
|
58
58
|
@parent_crumbs = @options[:parent_crumbs] || []
|
59
|
-
raise "parent_crumbs must be an Array ----> controller(:#{
|
59
|
+
raise "parent_crumbs must be an Array ----> controller(:#{controller_path})" if !@parent_crumbs.is_a?(Array)
|
60
60
|
end
|
61
61
|
|
62
62
|
def raise_if_any_invalid_option
|
63
63
|
invalid_option = (@options.keys - [:parent_crumbs]).first
|
64
|
-
raise "Invalid option :#{invalid_option} ----> controller(:#{
|
64
|
+
raise "Invalid option :#{invalid_option} ----> controller(:#{controller_path}, #{invalid_option}: '...') do" if invalid_option
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -7,14 +7,15 @@ module Bread
|
|
7
7
|
@controllers = {}
|
8
8
|
end
|
9
9
|
|
10
|
-
def controller(
|
11
|
-
|
10
|
+
def controller(controller_path, options={}, &block)
|
11
|
+
controller_path = controller_path.to_s
|
12
|
+
@controllers[controller_path] = controller_scope = ControllerScope.new(self, controller_path, options)
|
12
13
|
controller_scope.instance_eval(&block)
|
13
14
|
true
|
14
15
|
end
|
15
16
|
|
16
|
-
def get_controller_scope(
|
17
|
-
@controllers[
|
17
|
+
def get_controller_scope(controller_path)
|
18
|
+
@controllers[controller_path.to_s] || raise("no controller #{controller_path} in #{@controllers.keys}")
|
18
19
|
end
|
19
20
|
|
20
21
|
|
data/lib/bread/version.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
class ProductPhotosController < ApplicationController
|
2
|
-
|
3
|
-
|
2
|
+
# Use callbacks to share common setup or constraints between actions.
|
3
|
+
before_actions do
|
4
|
+
actions { @product = Product.find(params[:product_id]) }
|
5
|
+
actions(:index) { @product_photos = @product.product_photos }
|
6
|
+
actions(:new, :create) { @product_photo = @product.product_photos.build(product_photo_params) }
|
7
|
+
actions(:show, :edit, :update, :destroy) { @product_photo = @product.product_photos.find(params[:id]) }
|
8
|
+
end
|
4
9
|
|
5
10
|
# GET /product_photos
|
6
11
|
def index
|
7
|
-
@product_photos = @product.product_photos
|
8
12
|
end
|
9
13
|
|
10
14
|
# GET /product_photos/1
|
@@ -13,7 +17,6 @@ class ProductPhotosController < ApplicationController
|
|
13
17
|
|
14
18
|
# GET /product_photos/new
|
15
19
|
def new
|
16
|
-
@product_photo = @product.product_photos.build
|
17
20
|
end
|
18
21
|
|
19
22
|
# GET /product_photos/1/edit
|
@@ -22,8 +25,6 @@ class ProductPhotosController < ApplicationController
|
|
22
25
|
|
23
26
|
# POST /product_photos
|
24
27
|
def create
|
25
|
-
@product_photo = @product.product_photos.build(product_photo_params)
|
26
|
-
|
27
28
|
if @product_photo.save
|
28
29
|
redirect_to [@product, @product_photo], notice: 'Product photo was successfully created.'
|
29
30
|
else
|
@@ -50,18 +51,13 @@ class ProductPhotosController < ApplicationController
|
|
50
51
|
end
|
51
52
|
|
52
53
|
private
|
53
|
-
# Use callbacks to share common setup or constraints between actions.
|
54
|
-
|
55
|
-
def set_product
|
56
|
-
@product = Product.find(params[:product_id])
|
57
|
-
end
|
58
|
-
|
59
|
-
def set_product_photo
|
60
|
-
@product_photo = @product.product_photos.find(params[:id])
|
61
|
-
end
|
62
54
|
|
63
55
|
# Only allow a trusted parameter "white list" through.
|
64
56
|
def product_photo_params
|
65
|
-
params
|
57
|
+
if params[:product_photo]
|
58
|
+
params.require(:product_photo).permit(:name, :order)
|
59
|
+
else
|
60
|
+
{}
|
61
|
+
end
|
66
62
|
end
|
67
63
|
end
|
@@ -1,5 +1,10 @@
|
|
1
1
|
class ProductsController < ApplicationController
|
2
|
-
|
2
|
+
# Use callbacks to share common setup or constraints between actions.
|
3
|
+
before_actions do
|
4
|
+
actions(:new, :create) { @product = Product.new(product_params) }
|
5
|
+
actions(:show, :edit, :update, :destroy) { @product = Product.find(params[:id]) }
|
6
|
+
end
|
7
|
+
|
3
8
|
|
4
9
|
# GET /products
|
5
10
|
def index
|
@@ -56,13 +61,12 @@ class ProductsController < ApplicationController
|
|
56
61
|
end
|
57
62
|
|
58
63
|
private
|
59
|
-
# Use callbacks to share common setup or constraints between actions.
|
60
|
-
def set_product
|
61
|
-
@product = Product.find(params[:id])
|
62
|
-
end
|
63
|
-
|
64
64
|
# Only allow a trusted parameter "white list" through.
|
65
65
|
def product_params
|
66
|
-
params
|
66
|
+
if params[:product]
|
67
|
+
params.require(:product).permit(:name, :category)
|
68
|
+
else
|
69
|
+
{}
|
70
|
+
end
|
67
71
|
end
|
68
72
|
end
|
@@ -15,4 +15,18 @@ Bread.actions.config do
|
|
15
15
|
actions(:edit) { crumbs :@photos, :@photo, :@edit_photo }
|
16
16
|
end
|
17
17
|
|
18
|
+
|
19
|
+
#devise
|
20
|
+
controller 'devise/sessions' do
|
21
|
+
actions(:new) { crumbs :@root, :@devise_sign_in }
|
22
|
+
end
|
23
|
+
controller 'devise/registrations' do
|
24
|
+
actions(:new) { crumbs :@root, :@devise_sign_up }
|
25
|
+
actions(:edit) { crumbs :@root, :@devise_edit_user }
|
26
|
+
end
|
27
|
+
controller 'devise/passwords' do
|
28
|
+
actions(:new) { crumbs :@root, :@devise_sign_in, :@devise_remember }
|
29
|
+
actions(:edit) { crumbs :@root, :@devise_sign_in, :@devise_remember }
|
30
|
+
end
|
31
|
+
|
18
32
|
end
|
@@ -19,4 +19,11 @@ Bread.crumbs.config do
|
|
19
19
|
crumb(:@edit_photo) { to "Edit", h.edit_product_product_photo_path }
|
20
20
|
crumb(:@photo) { to @product_photo.unchanged_name, h.product_product_photo_path }
|
21
21
|
|
22
|
+
# devise
|
23
|
+
crumb(:@devise_sign_in) { to "Sign In", h.new_user_session_path }
|
24
|
+
crumb(:@devise_sign_up) { to "Sign Up", h.new_user_registration_path }
|
25
|
+
crumb(:@devise_edit_user) { to "Edit Profile", h.edit_user_registration_path }
|
26
|
+
crumb(:@devise_remember) { to "Forgot Password", h.new_user_password_path }
|
27
|
+
|
28
|
+
|
22
29
|
end
|
@@ -20,6 +20,13 @@
|
|
20
20
|
<p class="alert"><%= alert %></p>
|
21
21
|
|
22
22
|
|
23
|
+
<% if (current_user rescue false) %>
|
24
|
+
<p class="current_user"><%= current_user.email %></p>
|
25
|
+
<%= link_to "Sign Out", destroy_user_session_path, method: :delete %>
|
26
|
+
<% else %>
|
27
|
+
<p class="current_user">Guest</p>
|
28
|
+
<% end %>
|
29
|
+
|
23
30
|
|
24
31
|
<%= yield %>
|
25
32
|
|
@@ -30,6 +30,7 @@ Dummy::Application.configure do
|
|
30
30
|
# The :test delivery method accumulates sent emails in the
|
31
31
|
# ActionMailer::Base.deliveries array.
|
32
32
|
config.action_mailer.delivery_method = :test
|
33
|
+
config.action_mailer.default_url_options = {host: 'example.com'}
|
33
34
|
|
34
35
|
# Print deprecation notices to the stderr.
|
35
36
|
config.active_support.deprecation = :stderr
|
@@ -0,0 +1,146 @@
|
|
1
|
+
<% if namespaced? -%>
|
2
|
+
require_dependency "<%= namespaced_file_path %>/application_controller"
|
3
|
+
|
4
|
+
<% end -%>
|
5
|
+
<% module_namespacing do -%>
|
6
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
7
|
+
|
8
|
+
# load and authorize resources
|
9
|
+
before_actions do
|
10
|
+
#all actions
|
11
|
+
# actions { }
|
12
|
+
|
13
|
+
# building actions
|
14
|
+
actions(:new, :create) { @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %> }
|
15
|
+
|
16
|
+
# member actions, will raise a 404 if the model is not found
|
17
|
+
actions(
|
18
|
+
:show, :edit, :update, :destroy
|
19
|
+
) { @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %> }
|
20
|
+
end
|
21
|
+
|
22
|
+
authorize_resource
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
# GET <%= route_url %>
|
29
|
+
def index
|
30
|
+
@<%= plural_table_name %> = <%= orm_class.all(class_name) %>
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
# GET <%= route_url %>/1
|
37
|
+
# GET <%= route_url %>/1.json
|
38
|
+
def show
|
39
|
+
end
|
40
|
+
|
41
|
+
# GET <%= route_url %>/new
|
42
|
+
def new
|
43
|
+
end
|
44
|
+
|
45
|
+
# GET <%= route_url %>/1/edit
|
46
|
+
def edit
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
# POST <%= route_url %>
|
53
|
+
def create
|
54
|
+
if @<%= orm_instance.save %>
|
55
|
+
redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %>
|
56
|
+
else
|
57
|
+
render action: 'new'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# PATCH/PUT <%= route_url %>/1
|
62
|
+
def update
|
63
|
+
if @<%= orm_instance.update("#{singular_table_name}_params") %>
|
64
|
+
redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %>
|
65
|
+
else
|
66
|
+
render action: 'edit'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# DELETE <%= route_url %>/1
|
71
|
+
def destroy
|
72
|
+
if @<%= orm_instance.destroy %>
|
73
|
+
redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %>
|
74
|
+
else
|
75
|
+
render action: 'edit'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
# Only allow a trusted parameter "white list" through.
|
84
|
+
def <%= "#{singular_table_name}_params" %>
|
85
|
+
if params[<%= ":#{singular_table_name}" %>]
|
86
|
+
<%- if attributes_names.empty? -%>
|
87
|
+
params[<%= ":#{singular_table_name}" %>]
|
88
|
+
<%- else -%>
|
89
|
+
params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
|
90
|
+
<%- end -%>
|
91
|
+
else
|
92
|
+
{}
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
<% end -%>
|
97
|
+
|
98
|
+
|
99
|
+
################
|
100
|
+
# JSON BUILDER #
|
101
|
+
################
|
102
|
+
|
103
|
+
# # POST <%= route_url %>
|
104
|
+
# # POST <%= route_url %>.json
|
105
|
+
# def create
|
106
|
+
# respond_to do |format|
|
107
|
+
# if @<%= orm_instance.save %>
|
108
|
+
# format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %> }
|
109
|
+
# format.json { render action: 'show', status: :created, location: <%= "@#{singular_table_name}" %> }
|
110
|
+
# else
|
111
|
+
# format.html { render action: 'new' }
|
112
|
+
# format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
|
113
|
+
# end
|
114
|
+
# end
|
115
|
+
# end
|
116
|
+
|
117
|
+
# # PATCH/PUT <%= route_url %>/1
|
118
|
+
# # PATCH/PUT <%= route_url %>/1.json
|
119
|
+
# def update
|
120
|
+
# respond_to do |format|
|
121
|
+
# if @<%= orm_instance.update("#{singular_table_name}_params") %>
|
122
|
+
# format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> }
|
123
|
+
# format.json { render action: 'show', status: :ok, location: <%= "@#{singular_table_name}" %> }
|
124
|
+
# else
|
125
|
+
# format.html { render action: 'edit' }
|
126
|
+
# format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
|
127
|
+
# end
|
128
|
+
# end
|
129
|
+
# end
|
130
|
+
|
131
|
+
# # DELETE <%= route_url %>/1
|
132
|
+
# # DELETE <%= route_url %>/1.json
|
133
|
+
# def destroy
|
134
|
+
# respond_to do |format|
|
135
|
+
# if @<%= orm_instance.destroy %>
|
136
|
+
# format.html { redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %> }
|
137
|
+
# format.json { render action: 'index', status: :ok, location: <%= "@#{singular_table_name}" %> }
|
138
|
+
# else
|
139
|
+
# format.html { render action: 'edit' }
|
140
|
+
# format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
|
141
|
+
# end
|
142
|
+
# end
|
143
|
+
# end
|
144
|
+
|
145
|
+
|
146
|
+
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DeviseGuestNavigationTest < ActionDispatch::IntegrationTest
|
4
|
+
setup do
|
5
|
+
@email = 'test@gmail.com'
|
6
|
+
@password = '12345678'
|
7
|
+
@sample_user = User.create! email: @email, password: @password
|
8
|
+
end
|
9
|
+
|
10
|
+
test "should sign in" do
|
11
|
+
visit new_user_session_path
|
12
|
+
# bread
|
13
|
+
assert_crumb "Home"
|
14
|
+
assert_crumb "Sign In"
|
15
|
+
|
16
|
+
fill_in_email_password_click(@email, @password, nil, 'Sign in')
|
17
|
+
|
18
|
+
assert page.has_content?('Signed in successfully.'), page.body
|
19
|
+
end
|
20
|
+
|
21
|
+
test "shouldnt sign in" do
|
22
|
+
visit new_user_session_path
|
23
|
+
|
24
|
+
click_button('Sign in')
|
25
|
+
|
26
|
+
assert page.has_content?('Invalid email or password.'), page.body
|
27
|
+
end
|
28
|
+
|
29
|
+
test "should sign up" do
|
30
|
+
visit new_user_registration_path
|
31
|
+
# bread
|
32
|
+
assert_crumb "Home"
|
33
|
+
assert_crumb "Sign Up"
|
34
|
+
fill_in_email_password_click("new@gmail.com", @password, @password, 'Sign up')
|
35
|
+
|
36
|
+
assert page.has_content?('Welcome! You have signed up successfully.'), page.body
|
37
|
+
end
|
38
|
+
|
39
|
+
test "shouldnt sign up" do
|
40
|
+
visit new_user_registration_path
|
41
|
+
click_button('Sign up')
|
42
|
+
|
43
|
+
assert page.has_content?('prohibited this user from being'), page.body
|
44
|
+
end
|
45
|
+
|
46
|
+
test "should remember" do
|
47
|
+
visit new_user_password_path
|
48
|
+
# bread
|
49
|
+
assert_crumb "Home"
|
50
|
+
assert_crumb "Sign In"
|
51
|
+
assert_crumb "Forgot Password"
|
52
|
+
fill_in_email_password_click(@email, nil, nil, 'Send me')
|
53
|
+
|
54
|
+
assert page.has_content?('You will receive an email with instructions about how to reset your password in a few minutes.'), page.body
|
55
|
+
end
|
56
|
+
|
57
|
+
test "shouldnt remember when blank" do
|
58
|
+
visit new_user_password_path
|
59
|
+
click_button('Send me')
|
60
|
+
|
61
|
+
assert page.has_content?('prohibited this user from being'), page.body
|
62
|
+
end
|
63
|
+
|
64
|
+
test "shouldnt remember when wrong" do
|
65
|
+
visit new_user_password_path
|
66
|
+
fill_in_email_password_click('wrong', nil, nil, 'Send me')
|
67
|
+
|
68
|
+
assert page.has_content?('prohibited this user from being'), page.body
|
69
|
+
end
|
70
|
+
|
71
|
+
test "should edit password" do
|
72
|
+
raw_reset_password_token = User.last.send_reset_password_instructions
|
73
|
+
|
74
|
+
visit edit_user_password_path(reset_password_token: raw_reset_password_token)
|
75
|
+
|
76
|
+
# bread
|
77
|
+
assert_crumb "Home"
|
78
|
+
assert_crumb "Sign In"
|
79
|
+
assert_crumb "Forgot Password"
|
80
|
+
|
81
|
+
fill_in 'New password', with: '12341234'
|
82
|
+
fill_in 'Confirm new password', with: '12341234'
|
83
|
+
click_button 'Change'
|
84
|
+
|
85
|
+
assert page.has_content?('Your password was changed successfully. You are now signed in.'), page.body
|
86
|
+
end
|
87
|
+
|
88
|
+
test "shouldnt edit password when no token" do
|
89
|
+
visit edit_user_password_path
|
90
|
+
|
91
|
+
assert page.has_content?('please make sure you used the full URL provided.'), page.body
|
92
|
+
end
|
93
|
+
|
94
|
+
test "shouldnt edit password when no password" do
|
95
|
+
raw_reset_password_token = User.last.send_reset_password_instructions
|
96
|
+
|
97
|
+
visit edit_user_password_path(reset_password_token: raw_reset_password_token)
|
98
|
+
click_button 'Change'
|
99
|
+
|
100
|
+
assert page.has_content?('prohibited this user from being saved:'), page.body
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
class DeviseUserNavigationTest < ActionDispatch::IntegrationTest
|
106
|
+
setup do
|
107
|
+
@email = 'test@gmail.com'
|
108
|
+
@password = '12345678'
|
109
|
+
sign_in(@email, @password)
|
110
|
+
@new_password = '12341234'
|
111
|
+
end
|
112
|
+
|
113
|
+
test "should edit profile email" do
|
114
|
+
visit edit_user_registration_path
|
115
|
+
# bread
|
116
|
+
assert_crumb "Home"
|
117
|
+
assert_crumb "Edit Profile"
|
118
|
+
|
119
|
+
fill_in('Email', with: "omg-#{@email}")
|
120
|
+
fill_in('Current password', with: @password)
|
121
|
+
click_button 'Update'
|
122
|
+
|
123
|
+
assert page.has_content?('You updated your account successfully.'), page.body
|
124
|
+
end
|
125
|
+
|
126
|
+
test "shouldnt edit profile when no match" do
|
127
|
+
visit edit_user_registration_path
|
128
|
+
fill_in('Password', with: @new_password)
|
129
|
+
click_button 'Update'
|
130
|
+
|
131
|
+
assert page.has_content?("doesn't match"), page.body
|
132
|
+
end
|
133
|
+
|
134
|
+
test "shouldnt edit profile when current password is blank" do
|
135
|
+
visit edit_user_registration_path
|
136
|
+
fill_in('Password', with: @new_password)
|
137
|
+
fill_in('Password confirmation', with: @new_password)
|
138
|
+
click_button 'Update'
|
139
|
+
|
140
|
+
assert page.has_content?("can't be blank"), page.body
|
141
|
+
end
|
142
|
+
|
143
|
+
test "should edit profile password" do
|
144
|
+
visit edit_user_registration_path
|
145
|
+
fill_in('Current password', with: @password)
|
146
|
+
fill_in('Password', with: @new_password)
|
147
|
+
fill_in('Password confirmation', with: @new_password)
|
148
|
+
click_button 'Update'
|
149
|
+
|
150
|
+
assert page.has_content?("You updated your account successfully."), page.body
|
151
|
+
end
|
152
|
+
|
153
|
+
test "should remove profile" do
|
154
|
+
visit edit_user_registration_path
|
155
|
+
click_button 'Cancel my account'
|
156
|
+
|
157
|
+
assert page.has_content?('Bye! Your account was successfully cancelled. We hope to see you again soon.'), page.body
|
158
|
+
end
|
159
|
+
|
160
|
+
test "should sign out" do
|
161
|
+
click_link 'Sign Out'
|
162
|
+
|
163
|
+
assert page.has_content?('Signed out successfully.'), page.body
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
@@ -6,11 +6,32 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
def assert_crumb(text)
|
9
|
-
|
9
|
+
if response.present?
|
10
|
+
assert_select("ul#breadcrumbs li a", text, get_clean_response_body_error(text))
|
11
|
+
else
|
12
|
+
result = page.all("ul#breadcrumbs li a", text: text)
|
13
|
+
case result.count
|
14
|
+
when 0
|
15
|
+
assert(false, get_clean_response_body_error(text))
|
16
|
+
when 1
|
17
|
+
assert(true)
|
18
|
+
else
|
19
|
+
assert(false, get_clean_response_body_error(text))
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
10
23
|
end
|
11
24
|
|
12
25
|
def get_clean_response_body
|
13
|
-
response.
|
26
|
+
if response.present?
|
27
|
+
response
|
28
|
+
else
|
29
|
+
page
|
30
|
+
end.body.gsub("\n", '').gsub(' ', '')
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_clean_response_body_error(text)
|
34
|
+
"<li><a>#{text.magenta}</a></li> should be included exactly once in #{get_clean_response_body.blue} but wasn't"
|
14
35
|
end
|
15
36
|
|
16
37
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
def fill_in_email_password_click(email, password, password2, button_text)
|
5
|
+
fill_in('Email', with: email)
|
6
|
+
fill_in('Password', with: password) if password
|
7
|
+
fill_in('Password confirmation', with: password2) if password2
|
8
|
+
click_button button_text
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def sign_in(email, password)
|
13
|
+
User.create! email: email, password: password
|
14
|
+
|
15
|
+
visit new_user_session_path
|
16
|
+
fill_in_email_password_click(email, password, nil, 'Sign in')
|
17
|
+
|
18
|
+
assert page.has_content?('Signed in successfully.'), page.body
|
19
|
+
end
|
20
|
+
|
data/test/test_helper.rb
CHANGED
@@ -3,6 +3,7 @@ ENV["RAILS_ENV"] = "test"
|
|
3
3
|
|
4
4
|
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
5
|
require "rails/test_help"
|
6
|
+
require 'capybara/rails'
|
6
7
|
|
7
8
|
Rails.backtrace_cleaner.remove_silencers!
|
8
9
|
|
@@ -13,3 +14,8 @@ Dir["#{File.dirname(__FILE__)}/dummy/test/support/**/*.rb"].each { |f| require f
|
|
13
14
|
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
14
15
|
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
15
16
|
end
|
17
|
+
|
18
|
+
class ActionDispatch::IntegrationTest
|
19
|
+
# Make the Capybara DSL available in all integration tests
|
20
|
+
include Capybara::DSL
|
21
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bread
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thiago Pinto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- test/dummy/db/schema.rb
|
134
134
|
- test/dummy/db/test.sqlite3
|
135
135
|
- test/dummy/lib/assets/.keep
|
136
|
+
- test/dummy/lib/templates/rails/scaffold_controller/controller.rb
|
136
137
|
- test/dummy/log/.keep
|
137
138
|
- test/dummy/public/404.html
|
138
139
|
- test/dummy/public/422.html
|
@@ -146,11 +147,13 @@ files:
|
|
146
147
|
- test/dummy/test/fixtures/users.yml
|
147
148
|
- test/dummy/test/helpers/product_photos_helper_test.rb
|
148
149
|
- test/dummy/test/helpers/products_helper_test.rb
|
150
|
+
- test/dummy/test/integration/devise_test.rb
|
149
151
|
- test/dummy/test/integration/navigation_test.rb
|
150
152
|
- test/dummy/test/models/product_photo_test.rb
|
151
153
|
- test/dummy/test/models/product_test.rb
|
152
154
|
- test/dummy/test/models/user_test.rb
|
153
155
|
- test/dummy/test/support/asserts.rb
|
156
|
+
- test/dummy/test/support/others.rb
|
154
157
|
- test/test_helper.rb
|
155
158
|
homepage: https://github.com/hi/bread
|
156
159
|
licenses:
|
@@ -244,6 +247,7 @@ test_files:
|
|
244
247
|
- test/dummy/db/schema.rb
|
245
248
|
- test/dummy/db/test.sqlite3
|
246
249
|
- test/dummy/lib/assets/.keep
|
250
|
+
- test/dummy/lib/templates/rails/scaffold_controller/controller.rb
|
247
251
|
- test/dummy/log/.keep
|
248
252
|
- test/dummy/public/404.html
|
249
253
|
- test/dummy/public/422.html
|
@@ -257,9 +261,11 @@ test_files:
|
|
257
261
|
- test/dummy/test/fixtures/users.yml
|
258
262
|
- test/dummy/test/helpers/product_photos_helper_test.rb
|
259
263
|
- test/dummy/test/helpers/products_helper_test.rb
|
264
|
+
- test/dummy/test/integration/devise_test.rb
|
260
265
|
- test/dummy/test/integration/navigation_test.rb
|
261
266
|
- test/dummy/test/models/product_photo_test.rb
|
262
267
|
- test/dummy/test/models/product_test.rb
|
263
268
|
- test/dummy/test/models/user_test.rb
|
264
269
|
- test/dummy/test/support/asserts.rb
|
270
|
+
- test/dummy/test/support/others.rb
|
265
271
|
- test/test_helper.rb
|