-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Factory girl #25
base: main
Are you sure you want to change the base?
Factory girl #25
Conversation
This looks great at a glance @bradgreen3, thanks so much. I'll do a real review soon. So happy to have your interest in the project and would love to chat sometime about what brought you to it. If you're interested, please join us on waffle.io and assign tickets to yourself as you pick them up: https://waffle.io/lbraun/thanksgiving/join |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fantastic @bradgreen3, thanks. I hope all my comments aren't overwhelming. I like to do thorough reviews, especially at first, not to have control but just to get on the same page with collaborators. Please let me what is helpful and what isn't.
One minor thing I couldn't add as an inline comment: please remove spec/features/.DS_Store from your PR. You may want to add .DS_Store files to your global gitignore.
Lastly, I would appreciate your help as a new contributor to improve our documentation. Did you find any of it particularly useful when getting started? How could we make it better? Feel free to update it as you go!
Thanks again, and just let me know if you have any questions.
-Lucas
spec/support/feature_helpers.rb
Outdated
@@ -1,7 +1,9 @@ | |||
module FeatureHelpers | |||
def login_new_user(options = {}) | |||
visit "/" | |||
click_link "Sign in" | |||
within(:css, ".super-button") do | |||
click_link "Sign in or sign up" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please indent with two spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
spec/factories/users.rb
Outdated
sequence :name do |n| | ||
"Fake User#{n}" | ||
end | ||
approval_at "2017-02-25 23:28:13" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my experience with Factory Girl, the less you do in the main factory, the better. My rule of thumb is to only define attributes that are required (by a validation, for example). So if needed, we could add an approved_user factory, but I would take this line out here. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes perfect sense! Default approval status removed 😄
spec/factories/users.rb
Outdated
FactoryGirl.define do | ||
factory :user do | ||
provider "google_oauth2" | ||
sequence :uid do |n| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you write this using a more compact single-line block instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
spec/features/users_spec.rb
Outdated
context "when an admin visits the users index" do | ||
let!(:admin) { login_new_admin_user } | ||
let!(:users) { create_list(:user, 2) } | ||
let!(:unapproved_user) { create(:user, approval_at: nil)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a space after nil)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
spec/features/users_spec.rb
Outdated
} | ||
) | ||
it "sees a table with proper headers and rows" do | ||
expect(page).to have_css("#user_#{admin.id}", :text => "#{admin.name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use newer hash syntax instead of hash rockets:
https://github.com/bbatsov/ruby-style-guide#hash-literals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
spec/support/factories.rb
Outdated
@@ -0,0 +1,3 @@ | |||
FactoryGirl.define do | |||
# <factories for each model go here> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can get rid of this file since we are creating separate files for each model, don't you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, good call!
spec/support/feature_helpers.rb
Outdated
@@ -1,7 +1,9 @@ | |||
module FeatureHelpers | |||
def login_new_user(options = {}) | |||
visit "/" | |||
click_link "Sign in" | |||
within(:css, ".super-button") do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing the specs: I really shouldn't have pushed my last update without running them. Do you practice TDD? I'd like to make it the convention for this project.
CSS is the default selector for Capybara, so you can leave it out in cases like this: within(".super-button") do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem! It was a good way to get familiar with the code base! I do practice TDD, so I'll certainly use it if I add any new features.
Good catch. I'm not sure why I put that in there 😕
spec/factories/users.rb
Outdated
n | ||
end | ||
sequence :name do |n| | ||
"Fake User#{n}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please indent with two spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -39,4 +39,5 @@ group :development, :test do | |||
gem 'capybara' | |||
gem 'launchy' | |||
gem 'rspec-rails' | |||
gem 'factory_girl_rails' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💃 👍
spec/features/users_spec.rb
Outdated
|
||
before { visit users_index_path } | ||
it "sees a table with proper headers and rows" do | ||
expect(page).to have_css("#user_#{users.first.id}", :text => "#{users.first.name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no reason to use interpolation when you want to use the whole string ("#{x}" == x)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, you're absolutely right.
About half of the tests were failing, so I fixed them all and got Factory Girl set up in the process.
Closes #18