Skip to content

Factory girl - #25

Open
bradgreen3 wants to merge 15 commits into
lbraun:mainfrom
bradgreen3:factory-girl
Open

Factory girl#25
bradgreen3 wants to merge 15 commits into
lbraun:mainfrom
bradgreen3:factory-girl

Conversation

@bradgreen3

Copy link
Copy Markdown

About half of the tests were failing, so I fixed them all and got Factory Girl set up in the process.

Closes #18

@lbraun

lbraun commented Feb 27, 2017

Copy link
Copy Markdown
Owner

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

@lbraun lbraun left a comment

Copy link
Copy Markdown
Owner

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

Comment thread spec/support/feature_helpers.rb Outdated
visit "/"
click_link "Sign in"
within(:css, ".super-button") do
click_link "Sign in or sign up"

Copy link
Copy Markdown
Owner

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread spec/factories/users.rb Outdated
sequence :name do |n|
"Fake User#{n}"
end
approval_at "2017-02-25 23:28:13"

Copy link
Copy Markdown
Owner

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?

Copy link
Copy Markdown
Author

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 😄

Comment thread spec/factories/users.rb Outdated
FactoryGirl.define do
factory :user do
provider "google_oauth2"
sequence :uid do |n|

Copy link
Copy Markdown
Owner

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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread 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)}

Copy link
Copy Markdown
Owner

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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread 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}")

Copy link
Copy Markdown
Owner

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread spec/support/factories.rb Outdated
@@ -0,0 +1,3 @@
FactoryGirl.define do
# <factories for each model go here>

Copy link
Copy Markdown
Owner

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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good call!

Comment thread spec/support/feature_helpers.rb Outdated
def login_new_user(options = {})
visit "/"
click_link "Sign in"
within(:css, ".super-button") do

Copy link
Copy Markdown
Owner

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

Copy link
Copy Markdown
Author

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 😕

Comment thread spec/factories/users.rb Outdated
n
end
sequence :name do |n|
"Fake User#{n}"

Copy link
Copy Markdown
Owner

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread Gemfile
gem 'capybara'
gem 'launchy'
gem 'rspec-rails'
gem 'factory_girl_rails'

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃 👍

Comment thread 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}")

Copy link
Copy Markdown
Owner

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)

Copy link
Copy Markdown
Author

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.

@lbraun
lbraun changed the base branch from master to main August 8, 2020 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add FactoryGirl to the project

2 participants