Skip to content

Commit a385960

Browse files
Merge pull request #18 from calebowens/add-bullet
Install bullet gem and update readme
2 parents e3bf8ad + 5daf3da commit a385960

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ group :development do
7777

7878
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
7979
# gem "spring"
80+
81+
gem "bullet"
8082
end
8183

8284
group :test do

Gemfile.lock

+5
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ GEM
106106
bootsnap (1.18.3)
107107
msgpack (~> 1.2)
108108
builder (3.2.4)
109+
bullet (7.1.6)
110+
activesupport (>= 3.0.0)
111+
uniform_notifier (~> 1.11)
109112
capybara (3.40.0)
110113
addressable
111114
matrix
@@ -334,6 +337,7 @@ GEM
334337
tzinfo (2.0.6)
335338
concurrent-ruby (~> 1.0)
336339
unicode-display_width (2.5.0)
340+
uniform_notifier (1.16.0)
337341
validates_email_format_of (1.7.2)
338342
i18n
339343
web-console (4.2.1)
@@ -358,6 +362,7 @@ PLATFORMS
358362
DEPENDENCIES
359363
bcrypt (~> 3.1.7)
360364
bootsnap
365+
bullet
361366
capybara
362367
cuprite
363368
dartsass-rails (~> 0.5.0)

config/environments/development.rb

+6
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,10 @@
6565
config.middleware.use(JsRoutes::Middleware)
6666

6767
config.web_console.permissions = "0.0.0.0/0"
68+
69+
config.after_initialize do
70+
Bullet.enable = true
71+
Bullet.alert = true
72+
Bullet.rails_logger = true
73+
end
6874
end

readme.md

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# README
22

3+
## Production Readyness
4+
5+
There are two goals for this project
6+
1. To try and build a starting point which I can use to put together a project in a very short amount of time.
7+
2. To try and answer some of the "what ifs" that I end up thinking about at my day job, but would be wholly
8+
inapropriate to implement in a work setting due to their "unrailsy" nature
9+
10+
While this is a project that I'm using in apps that I hope will serve real customers, and I'm putting a reasonable
11+
effort into mantaining this. Given the fact that there are experiemental code structure choises and dev builds
12+
importmaps, caution is advised!
13+
314
## Development environment setup
415

516
### Pre-Commit Hooks
@@ -60,6 +71,7 @@ Everyone should have pre-commit hooks setup!
6071
omniauth, or replace with another authentication system.
6172
- Caching
6273
- [Solid Cache](https://github.com/rails/solid_cache)
74+
- N+1 catching via [Bullet](https://github.com/flyerhzm/bullet)
6375

6476
## Style
6577

@@ -110,13 +122,17 @@ class Authentication::Pages::LoginController < ApplicationController
110122
validates_presence_of :email
111123
validates_presence_of :password
112124

125+
validate :ensure_user_exists # Must run last for security
126+
113127
def user
114128
@user ||= User.from_login_details(email:, password:)
115129
end
116130

117131
def ensure_user_exists
132+
return unless errors.blank?
133+
118134
if user.nil?
119-
errors.add :email, :no_user, message: "The email and password provided did not match our records"
135+
errors.add :email, :no_user, message: "and password provided did not match our records"
120136
end
121137
end
122138
end
@@ -156,11 +172,7 @@ class Authentication::Pages::LoginController < ApplicationController
156172
def submit
157173
ViewContext.form_object = FormObject.new(user_params)
158174

159-
if ViewContext.form_object.validations_passed?
160-
ViewContext.form_object.ensure_user_exists
161-
end
162-
163-
if ViewContext.form_object.validations_passed?
175+
if ViewContext.form_object.valid?
164176
ViewContext.form_object.user.add_to_session(session)
165177

166178
redirect_to dashboard_home_path, status: :see_other
@@ -181,5 +193,3 @@ class Authentication::Pages::LoginController < ApplicationController
181193
end
182194
end
183195
```
184-
185-

0 commit comments

Comments
 (0)