Useless assignments fixed, and rails 4 stuff. #1094

Merged
merged 28 commits into from Dec 4, 2016

Projects

None yet

7 participants

@Br3nda
Contributor
Br3nda commented Nov 29, 2016

Fixes

  • use of dynamic find_by
  • before_filter is now before_action in rails 4
  • allows two special files to call puts
  • fixed up useless assignments
@maco maco added the in progress label Nov 29, 2016
@@ -87,7 +87,7 @@ def load_test_users
suburb_file.pos = 0 if suburb_file.eof?
row = CSV.parse(suburb_file.readline)
- suburb, country, state, latitude, longitude = row[0]
+ suburb, _country, _state, latitude, longitude = row[0]
@maco
maco Nov 29, 2016 Member

what're the underlines?

@Br3nda
Br3nda Nov 29, 2016 Contributor

They indicate that the variable is not going to be used. That's it's okay for linter to ignore this assignment to a useless variable.

@Br3nda
Br3nda Nov 29, 2016 Contributor

it raises the question: Why do we have country and state in the csv file if we don't use it...

@pozorvlak
pozorvlak Nov 30, 2016 Member

@maco: yep, "variable starting with underscore" is a fairly widespread convention for either "private variable" or "variable that can be ignored".

@Br3nda: Good question. This code was merged in #731, and the discussion there doesn't explain where the file suburbs.csv came from. It looks like it's a list of Australian suburbs generated for some other purpose and included wholesale - an Australian government database, perhaps? We should probably know more about its origin, to check we're not causing any licensing issues. @oshiho3, where did that file come from?

@oshiho3
oshiho3 Nov 30, 2016 Contributor

Unfortunately, I can't remember where I pulled the suburbs.csv. The purpose of the file was to improve the speed of generating test users. I remember there was a view that shows a number of growers/gardens in bubbles on a map. I think geolocation was normally pulled from external geocoding service when an address was entered in on a user record. Doing this for all test users was causing long wait.
I hope this information helps.

@Br3nda
Br3nda Nov 30, 2016 Contributor

We could remove that file and instead use the Faker gem.

@coveralls
coveralls commented Nov 29, 2016 edited

Coverage Status

Coverage increased (+0.03%) to 87.367% when pulling 178c181 on Br3nda:bw/useless-assignments into 7b0fdcf on Growstuff:dev.

app/controllers/seeds_controller.rb
@@ -49,7 +49,7 @@ def new
@seed = Seed.new
# using find_by_id here because it returns nil, unlike find
- @crop = Crop.find_by_id(params[:crop_id]) || Crop.new
+ @crop = Crop.find_by(id: params[:crop_id]) || Crop.new
@maco
maco Nov 29, 2016 Member

Code Climate is pointing out that alternate_names_controller.rb and ....something else... have practically this same chunk of code in new() and I'm left wondering, given existence of load_and_authorize_resource and load_resource in cancan, do we need to find these by id manually?

Ok, I'm also wondering why we'd be creating a seed for a crop that doesn't exist.

@Br3nda
Br3nda Nov 29, 2016 Contributor

I haven't used cancan much but i thought load_and_authorize_resource would only load the @seed on the seeds controller. The @crop and @owner needs to be loaded by the method that needs it.

@CloCkWeRX
CloCkWeRX Nov 30, 2016 edited Contributor

Its the

using find_by_id here because it returns nil, unlike find

bit that makes it different.

@Br3nda
Br3nda Nov 30, 2016 Contributor

Can you sum up this? Should it be changed back? Is it okay like this?

@CloCkWeRX
CloCkWeRX Nov 30, 2016 Contributor

Its OK as is (maybe adjust comment), it was more why we can't use load_resource or similar there

@maco
Member
maco commented Nov 29, 2016
@Br3nda Br3nda Rails dynamic finds fixed
a2e86b3
@coveralls

Coverage Status

Coverage increased (+0.03%) to 87.367% when pulling a2e86b3 on Br3nda:bw/useless-assignments into 7b0fdcf on Growstuff:dev.

@coveralls

Coverage Status

Coverage increased (+0.03%) to 87.367% when pulling a2e86b3 on Br3nda:bw/useless-assignments into 7b0fdcf on Growstuff:dev.

@Br3nda
Contributor
Br3nda commented Nov 30, 2016

i forgot the --rails when i tested this on my laptop.

sorting these last rubocop issues

@maco
Member
maco commented Nov 30, 2016

I vote ignoring those 3 code climate issues about duplication in controllers, at least for now. We do have a comment somewhere suggesting we look at RABL, and https://github.com/plataformatec/responders is also a possibility when tackling "wow, our controllers are just piles of scaffolding" becomes a high priority.

spec/features/unsubscribing_spec.rb
@@ -52,7 +52,7 @@
# visit /members/unsubscribe/somestring ie.parameter to the URL is a random string
visit unsubscribe_member_url("type=send_planting_reminder&member_id=#{member.id}")
expect(page).to have_content "We're sorry, there was an error"
- updated_member = Member.find(member.id) # reload the member
+ Member.find(member.id) # reload the member
@CloCkWeRX
CloCkWeRX Nov 30, 2016 Contributor

That seems unused

@Br3nda
Br3nda Nov 30, 2016 Contributor

true! will fix.

@@ -23,7 +23,6 @@
description: 'a' * 130
)
result = helper.display_garden_description(garden)
- link = link_to("Read more", garden_path(garden))
expect(result).to eq 'a' * 130
@CloCkWeRX
CloCkWeRX Nov 30, 2016 Contributor

Thats a really weird expectation; like something was lost in refactoring

@@ -90,7 +90,7 @@
context 'ordering' do
it "should be sorted alphabetically" do
- z = FactoryGirl.create(:garden_z)
+ FactoryGirl.create(:garden_z)
a = FactoryGirl.create(:garden_a)
@CloCkWeRX
CloCkWeRX Nov 30, 2016 Contributor

This one might have been better fixed by fleshing out the other expectation (garden.last == z)

@CloCkWeRX

LGTM - its a bit of a mishmash of changes, but the invidual commits make sense.

One or two spots with unused code, and a few other .where(...).first => find_by warnings exist still, would be good to clean that up.

@maco
Member
maco commented Nov 30, 2016
Br3nda added some commits Nov 30, 2016
@Br3nda Br3nda removed member look up that wasn't used in spec
cd0e287
@Br3nda Br3nda Merge branch 'dev' into bw/useless-assignments
b454132
@coveralls
coveralls commented Nov 30, 2016 edited

Coverage Status

Coverage increased (+0.03%) to 87.472% when pulling b454132 on Br3nda:bw/useless-assignments into 547e640 on Growstuff:dev.

@coveralls
coveralls commented Nov 30, 2016 edited

Coverage Status

Coverage increased (+0.03%) to 87.472% when pulling b454132 on Br3nda:bw/useless-assignments into 547e640 on Growstuff:dev.

Br3nda added some commits Dec 1, 2016
@Br3nda Br3nda Turn on rails:true in rubocop
so we don't need to pass --rails
e06d110
@Br3nda Br3nda Moved login_name_or_email query to own method
ae26e3f
@Br3nda Br3nda Moved case-insensitve login look up to method
37adbe5
@Br3nda Br3nda Convert where.first to find_by
cba02ae
@coveralls
coveralls commented Dec 1, 2016 edited

Coverage Status

Coverage increased (+0.03%) to 87.472% when pulling cba02ae on Br3nda:bw/useless-assignments into 547e640 on Growstuff:dev.

@coveralls

Coverage Status

Coverage increased (+0.06%) to 87.494% when pulling cba02ae on Br3nda:bw/useless-assignments into 547e640 on Growstuff:dev.

Br3nda added some commits Dec 1, 2016
@Br3nda Br3nda use Member.case_insensitive_login_name dc504fe
@Br3nda Br3nda Case insensitive crop look up
aba06c1
@coveralls
coveralls commented Dec 1, 2016 edited

Coverage Status

Coverage increased (+0.07%) to 87.506% when pulling aba06c1 on Br3nda:bw/useless-assignments into 547e640 on Growstuff:dev.

Br3nda and others added some commits Dec 1, 2016
@Br3nda Br3nda change where.first -> find_by d2fb96b
@CloCkWeRX CloCkWeRX Merge branch 'dev' into bw/useless-assignments
7032436
@@ -196,6 +196,10 @@ def interesting?
return false
end
+ def Member.login_name_or_email(login)
@CloCkWeRX
CloCkWeRX Dec 1, 2016 Contributor

Later on, should swap that to pure scope syntax

@Br3nda
Br3nda Dec 2, 2016 Contributor

I started with scopes - but the railsguide on how to do scopes says a class method is preferrable to a scope with a variable pass in.
http://guides.rubyonrails.org/active_record_querying.html#passing-in-arguments

However, this is just duplicating the functionality that would be provided to you by a class method.
...
Using a class method is the preferred way to accept arguments for scopes.

@CloCkWeRX
Contributor

Still LGTM

Br3nda added some commits Dec 1, 2016
@Br3nda Br3nda Merge remote-tracking branch 'origin/bw/find-by' into bw/useless-assi…
…gnments
d87de13
@Br3nda Br3nda use find_or_initialize_by
03cb4a8
@Br3nda
Contributor
Br3nda commented Dec 2, 2016

I'd like someone who understands the growstuff SSO to test this - there are changes in the warden lookup, so someone checking we're still secure is wise.

(I don't use facebook, cos their T&S aren't for me)

Br3nda added some commits Dec 2, 2016
@Br3nda Br3nda Merge branch 'dev' into bw/useless-assignments
bb0eb25
@Br3nda Br3nda Merge branch 'dev' into bw/useless-assignments
1388aa3
@coveralls
coveralls commented Dec 2, 2016 edited

Coverage Status

Coverage increased (+0.07%) to 87.743% when pulling 1388aa3 on Br3nda:bw/useless-assignments into 519cf80 on Growstuff:dev.

@CloCkWeRX CloCkWeRX Merge branch 'dev' into bw/useless-assignments
afbdd11
@CloCkWeRX
Contributor

I'd like someone who understands the growstuff SSO to test this - there are changes in the warden lookup, so someone checking we're still secure is wise.

I must have missed that, unless you mean the before_filter => before_action changes. http://stackoverflow.com/questions/16519828/rails-4-before-filter-vs-before-action covers that

Did you mean something else?

@coveralls

Coverage Status

Coverage increased (+0.07%) to 87.749% when pulling afbdd11 on Br3nda:bw/useless-assignments into 04ba871 on Growstuff:dev.

@coveralls

Coverage Status

Coverage increased (+0.07%) to 87.749% when pulling afbdd11 on Br3nda:bw/useless-assignments into 04ba871 on Growstuff:dev.

@Br3nda
Contributor
Br3nda commented Dec 3, 2016

@clockwerx I mean the query change in find_first_by_auth_conditions

@CloCkWeRX CloCkWeRX Merge branch 'dev' into bw/useless-assignments
c43ec3d
@coveralls

Coverage Status

Coverage increased (+0.07%) to 87.76% when pulling c43ec3d on Br3nda:bw/useless-assignments into 1ae9366 on Growstuff:dev.

@coveralls

Coverage Status

Coverage increased (+0.07%) to 87.76% when pulling c43ec3d on Br3nda:bw/useless-assignments into 1ae9366 on Growstuff:dev.

@Br3nda Br3nda merged commit 0fcd8c8 into Growstuff:dev Dec 4, 2016

1 of 2 checks passed

Details codeclimate Code Climate found 4 new issues and 3 fixed issues.
Details continuous-integration/travis-ci/pr The Travis CI build passed
@maco maco removed the in progress label Dec 4, 2016
@Br3nda Br3nda deleted the Br3nda:bw/useless-assignments branch Dec 4, 2016
@CloCkWeRX
Contributor

Ah thats all fine.

@cesy cesy added this to the Release 17 milestone Dec 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment