Skip to content
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

[20325][20701] Replace dynamic finders, fix ActiveRecord deprecation warnings #3194

Merged

Conversation

myabc
Copy link
Contributor

@myabc myabc commented Jun 29, 2015

💁 This PR doesn't deal with deprecation warnings that are not ActiveRecord related.

Supercedes #3186

https://community.openproject.org/work_packages/20325
https://community.openproject.org/work_packages/20701

@TeatroIO
Copy link

I've prepared a stage to preview changes. Open stage or view logs.

@@ -153,7 +153,7 @@
let(:child_project) { FactoryGirl.create(:project, parent: project) }
let(:shared_version) { FactoryGirl.create(:version, project: project, sharing: 'descendants') }

before { get :index, ids: shared_version.id.to_s, project_id: child_project.id, format: :json }
before do get :index, ids: shared_version.id.to_s, project_id: child_project.id, format: :json end

Choose a reason for hiding this comment

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

Line is too long. [108/100]

myabc added 5 commits June 30, 2015 11:50
This patch replaces all dynamic finders, for the sake of consistency,
although only some methods are deprecated. See:
https://github.com/rails/activerecord-deprecated_finders#active-record-deprecated-finders

* Revert some `User#find_by_login` usages in cuke steps accidentally
  removed in 74228b5.

User Story # 20325

Signed-off-by: Alex Coles <[email protected]>
`.find_or_create_by` will call `.first`.

Signed-off-by: Alex Coles <[email protected]>
@@ -128,8 +128,7 @@ def migrate_planning_element_types(timelines_opts, pe_type_id_map, calling_class

calling_class.contains_none_element = calling_class.contains_none_element? || pe_types.empty?

pe_types = pe_types.empty? ? new_ids_of_former_pes
: pe_types.map { |p| pe_type_id_map[p.to_i].to_s }
pe_types = pe_types.empty? ? new_ids_of_former_pes : pe_types.map { |p| pe_type_id_map[p.to_i].to_s }

Choose a reason for hiding this comment

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

Line is too long. [105/100]

@NobodysNightmare
Copy link
Contributor

You should see my hint on calling Project.allowed_to_condition, includes and references as a more general advice. I've seen this pattern with other methods too, where the caller uses some kind of condition he really doesn't know, but for some reason starts to include and reference fancy tables. Sometimes acompanied with a comment that excuses for this.

I think since the introduction of references only amplifies that (already existing) problem, we should at least start to look for a way out for the worst offenders.

@NobodysNightmare
Copy link
Contributor

Pew... reviewed until the latest commit:

Revert "DRY WorkPackageSchema#available_custom_fields spec" … 0436446

Looking nice (and tedious) :)

myabc added 3 commits July 8, 2015 11:04
Reported as issue upstream:
rubocop/rubocop#2021

[ci skip]

Signed-off-by: Alex Coles <[email protected]>
[ci skip]

Signed-off-by: Alex Coles <[email protected]>
Missed by rubocop auto-correct.

[ci skip]

Signed-off-by: Alex Coles <[email protected]>
current_language.to_s.downcase == 'ja' ||
current_language.to_s.downcase == 'zh' ||
current_language.to_s.downcase == 'zh-tw' ||
if current_language.to_s.downcase == 'ko' || current_language.to_s.downcase == 'ja' || current_language.to_s.downcase == 'zh' || current_language.to_s.downcase == 'zh-tw' ||

Choose a reason for hiding this comment

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

Line is too long. [178/100]
Unnecessary spacing detected.

current_language.to_s.downcase == 'ja' ||
current_language.to_s.downcase == 'zh' ||
current_language.to_s.downcase == 'zh-tw' ||
if current_language.to_s.downcase == 'ko' || current_language.to_s.downcase == 'ja' || current_language.to_s.downcase == 'zh' || current_language.to_s.downcase == 'zh-tw' ||

Choose a reason for hiding this comment

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

Line is too long. [178/100]
Unnecessary spacing detected.

@myabc
Copy link
Contributor Author

myabc commented Jul 9, 2015

@NobodysNightmare

Pew... reviewed until the latest commit:

Thanks!

Looking nice (and tedious) :)

Yes, sure is tedious.

I think I've now dealt with all of your comments, with the exception of reordering references in query chains. As we already discussed, there may be some references that can be removed once we're on Rails 4.1.

tl; dr: sometimes an automatic tool just fails to do the right thing
I am not sure how we want to deal with this problem in general. Arguably these changes by you make the overall situation better, while introducing collateral damage. That is why I am inclined to merge those changes regardless.
But I don't feel like we will be able to keep "100% rubocop -a compatibility" in the long term. I don't know if this is a problem...

I reported one of the issues upstream (rubocop/rubocop#2021). I tend to be optimistic though, and think rubocop can only get better at linting/auto-correcting code. It's annoying though that Hound is still on a slightly older version of rubocop and that there are some discrepancies in configurations.

@@ -164,7 +165,7 @@ def find_all_projects_by_project_id
# WTF. Why do we completely skip rewiring in this case and always provide parent_ids?
# This is totally inconistent.
identifiers = params[:ids].split(/,/).map(&:strip)
@planning_elements = WorkPackage.visible(User.current).find_all_by_id(identifiers)
@planning_elements = WorkPackage.visible(User.current).where(id: identifiers)
Copy link
Contributor

Choose a reason for hiding this comment

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

This now returns an ActiveRecord::Relation. Don't know if that is a problem, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ulferts that shouldn't be a problem.

@ulferts
Copy link
Contributor

ulferts commented Jul 10, 2015

@myabc I am done with my review and once I received statements to my comments, willing to merge this PR.

Thanks for the huge amount of work you have put in here!

ulferts added a commit that referenced this pull request Jul 10, 2015
…ynamic-finders

[20325][20701] Replace dynamic finders, fix ActiveRecord deprecation warnings
@ulferts ulferts merged commit c13aa00 into opf:feature/rails4 Jul 10, 2015
@myabc myabc deleted the feature/20325-rails4-deprecated-dynamic-finders branch July 13, 2015 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

7 participants