Skip to content

Commit

Permalink
Ao3 5022 rails 4 dot 1 (#2927)
Browse files Browse the repository at this point in the history
* AO3-5022 Bump Rails to 4.1.16

* AO3-5022 Remove with_scope on Work model

* AO3-5022 Bump Authlogic version

* AO3-5022 Bump to Authlogic 3.4.6

* AO3-5022 Resolve old association syntax for archive_faq

* Fixes triggering of CSRF protection in bookmarks controller spec

`get :action, format: :js` triggers CSRF protection in Rails 4.1
Replace with `xhr :get, :action, format: :js`

* Re-adds support for Minitest assertions in Cucumber steps

* Fixes Authlogic::Session::Activateion::NotActivated error in logout user step

* Fixes login step authlogic bugs

* Removes 'group_by' virtual attribute if @fandoms is empty in users controller

* Updates syntax for getting all Language ordered by short

* Fixes admin invitations feature specs

The old syntax `find(:all)` or `find(:first)` is incorrect - find now only
accepts one argument, which it expects to be the id of the object it's looking
for. This should fix the remaining spec failures in admin_invitations.feature

* Fixes syntax for scope on user

* Adds link_to_function helper

This is in place of rewriting the html/javascript everywhere to be unobtrusive:

http://guides.rubyonrails.org/working_with_javascript_in_rails.html#unobtrusive_javascript

Which is the recommended approach.

* Fixes query syntax in scope in Question model

* Fixes MySql2 syntax error by calling 'size' instead of 'count'

The bug this is addressing is described here:

rails/rails#15138

I chose to use `size` in these cases because the collections are already
loading. This by-steps the bug and isn't making another call to the database.

* Fixes problem with AR query in SeriesController

* Fix AR queries in Pseud model

* Fixes the calling of a virtual attribute on an empty array of Fandom objects in
the pseuds controller

* Fixes AR query syntax errors found in comments_and_kudos/kudos.feature

* Refactors helper method to eliminate bug

Can't call `size` on a collection that hasn't been loaded, and `count` needs to
go because of the known 4.1 but with select and count.

* Fixes AR query syntax in pseud model scope

* Fixes MySql count with select bug in challenge assignments partial

Removes whitespace

* Fixes bug where `size` was being called on `nil`

* Fixes bug with order of operations

one = 'one' && true will make one == true and return true
(one = 'one') && true will make one == 'one' and return true

* Adds rails_select_on_includes gem

This fixes a problem raised in the UsersController (and potentially elsewhere)
where Mysql was blowing up because a virtual attribute defined in a select
statement wasn't a database column.

See the issue this is discussed in: rails/rails#15185
And the Gem: https://github.com/alekseyl/rails_select_on_includes

* Commits Gemfile.lock

* Fixes `Mysql2::Error: Unknown column 'users.login'` in pseud model

Eager loading the user in two queries in the pseud model (the `by_byline` scope
and the `parse_byline` method) was causing Mysql to throw an Unknown column
error. Using a join instead fixes the problem.

* Fixes problem with includes statement

The includes statements in question referenced a has_many association that used
conditions (approved_conditions) that applied to an association of the
association. (`Work.includes(:approved_collections)` where `approved_collections`
are conditions that have collections that meet a certain criteria). By
moving the scopes that determine whether a collection is
approved/rejected/approved by user into the collectible model, the Work model
doesn't have to guess what is meant by the reference to the columns
`collection_items.attributes`.

* Removes rails_select_on_includes

It caused all other previously passing tests to start failing and didn't end up
actually solving the problem it was supposed to.

* Calls load on @fandoms in UsersController to make sure it's loaded before the
view calls `.empty?` on it

* Fixes `find :all` reference

* Fixes outdated `find :all` reference

* Fixes 'count' bug

* Fixes typo in pseud model scope

* Fixes outdated `find :all` syntax in media and tags controllers

* Calls `load` on @fandoms variable in pseuds controller to prevent `empty?` from
erroring out when it's called on @fandoms in the view

* Fixes outed `find(:first...) syntax in app/helpers/tag_helpers

* Adds Authlogic fix to tag steps that need it

* Fixes variable reference

* Fixes Authlogic problem with deleting account step

* Fixes feature failures in users caused by outdated `find :all` syntax

* Fixes works feature failures by updated outdated `find :all` syntax

* Fixes challenge_signups_controller_spec failure

* Fixes get requests with js format returning cross origin not allowed error

in comments controller spec

* Checks that expected params exist before passing them to update_attributes

* Fixes get ... format: :js line to not raise cross origin error

* Fixes outdated `find(:all)` syntax in tags controller

* Try

* Assign varible

* Try this

* And the second case

* Corgis are still lovely

* Fixes mysql syntax problem with `count` in SpamReport method

* Shortens syntax in external authors controller conditional

* Adds TODO/note about link_to_function definition

* Fixes typo in work model

* Removes duplicate line in user step definition

* Removes comment for useless gem

* Makes stylistic change - `size == 0` is better as `size.zero?`
  • Loading branch information
Wendy authored and zz9pzza committed Jun 5, 2017
1 parent c277d37 commit 38f6080
Show file tree
Hide file tree
Showing 36 changed files with 249 additions and 152 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Expand Up @@ -5,7 +5,7 @@ gem 'test-unit', '~> 3.0'

gem 'bundler'

gem 'rails', '4.0.13'
gem 'rails', '4.1.16'

gem 'rails-observers'
gem 'actionpack-page_caching'
Expand Down Expand Up @@ -74,7 +74,7 @@ gem 'fastimage'
# Gems for authentication
gem 'devise'
gem 'devise-async' # To mails through queues
gem 'authlogic', '~> 3.3.0'
gem 'authlogic', '~> 3.4.6'
gem 'bcrypt'

# A highly updated version of the authorization plugin
Expand Down
108 changes: 61 additions & 47 deletions Gemfile.lock
Expand Up @@ -2,57 +2,61 @@ GEM
remote: https://rubygems.org/
specs:
aaronh-chronic (0.3.9)
actionmailer (4.0.13)
actionpack (= 4.0.13)
actionmailer (4.1.16)
actionpack (= 4.1.16)
actionview (= 4.1.16)
mail (~> 2.5, >= 2.5.4)
actionpack (4.0.13)
activesupport (= 4.0.13)
builder (~> 3.1.0)
erubis (~> 2.7.0)
actionpack (4.1.16)
actionview (= 4.1.16)
activesupport (= 4.1.16)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
actionpack-page_caching (1.1.0)
actionpack (>= 4.0.0, < 6)
activemodel (4.0.13)
activesupport (= 4.0.13)
builder (~> 3.1.0)
activerecord (4.0.13)
activemodel (= 4.0.13)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.13)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.4)
actionview (4.1.16)
activesupport (= 4.1.16)
builder (~> 3.1)
erubis (~> 2.7.0)
activemodel (4.1.16)
activesupport (= 4.1.16)
builder (~> 3.1)
activerecord (4.1.16)
activemodel (= 4.1.16)
activesupport (= 4.1.16)
arel (~> 5.0.0)
activerecord-mysql-reconnect (0.4.0)
activerecord
mysql2
activesupport (4.0.13)
activesupport (4.1.16)
i18n (~> 0.6, >= 0.6.9)
minitest (~> 4.2)
multi_json (~> 1.3)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
tzinfo (~> 1.1)
acts_as_list (0.9.5)
activerecord (>= 3.0)
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
akismetor (1.0.0)
ansi (1.5.0)
arel (4.0.2)
arel (5.0.1.20140414130214)
audited (4.4.1)
activerecord (>= 4.0, < 5.2)
authlogic (3.3.0)
authlogic (3.4.6)
activerecord (>= 3.2)
activesupport (>= 3.2)
aws-sdk (2.9.17)
aws-sdk-resources (= 2.9.17)
aws-sdk-core (2.9.17)
request_store (~> 1.0)
scrypt (>= 1.2, < 3.0)
aws-sdk (2.9.18)
aws-sdk-resources (= 2.9.18)
aws-sdk-core (2.9.18)
aws-sigv4 (~> 1.0)
jmespath (~> 1.0)
aws-sdk-resources (2.9.17)
aws-sdk-core (= 2.9.17)
aws-sdk-resources (2.9.18)
aws-sdk-core (= 2.9.18)
aws-sigv4 (1.0.0)
bcrypt (3.1.11)
builder (3.1.4)
builder (3.2.3)
bullet (5.0.0)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.9.0)
Expand Down Expand Up @@ -166,6 +170,9 @@ GEM
multipart-post (>= 1.2, < 3)
fastimage (2.1.0)
ffi (1.9.18)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
gherkin (3.2.0)
globalize (4.0.3)
activemodel (>= 4.0.0, < 5)
Expand All @@ -177,18 +184,18 @@ GEM
htmlentities (4.3.4)
http-cookie (1.0.3)
domain_name (~> 0.5)
httparty (0.15.2)
httparty (0.15.3)
multi_xml (>= 0.5.2)
i18n (0.8.1)
jmespath (1.3.1)
json (2.1.0)
json (1.8.6)
kgio (2.10.0)
launchy (2.4.3)
addressable (~> 2.3)
lograge (0.5.0)
actionpack (>= 4, <= 5.1.0)
activesupport (>= 4, <= 5.1.0)
railties (>= 4, <= 5.1.0)
lograge (0.5.1)
actionpack (>= 4, < 5.2)
activesupport (>= 4, < 5.2)
railties (>= 4, < 5.2)
mail (2.6.5)
mime-types (>= 1.16, < 4)
mechanize (2.7.5)
Expand All @@ -204,7 +211,7 @@ GEM
mime-types (2.99.3)
mimemagic (0.3.0)
mini_portile2 (2.1.0)
minitest (4.7.5)
minitest (5.10.2)
mono_logger (1.1.0)
multi_json (1.12.1)
multi_test (0.1.2)
Expand Down Expand Up @@ -266,26 +273,29 @@ GEM
rack
rack-test (0.6.3)
rack (>= 1.0)
rails (4.0.13)
actionmailer (= 4.0.13)
actionpack (= 4.0.13)
activerecord (= 4.0.13)
activesupport (= 4.0.13)
rails (4.1.16)
actionmailer (= 4.1.16)
actionpack (= 4.1.16)
actionview (= 4.1.16)
activemodel (= 4.1.16)
activerecord (= 4.1.16)
activesupport (= 4.1.16)
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.13)
railties (= 4.1.16)
sprockets-rails (~> 2.0)
rails-observers (0.1.2)
activemodel (~> 4.0)
railties (4.0.13)
actionpack (= 4.0.13)
activesupport (= 4.0.13)
railties (4.1.16)
actionpack (= 4.1.16)
activesupport (= 4.1.16)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
raindrops (0.18.0)
rake (12.0.0)
redis (3.3.3)
redis-namespace (1.5.3)
redis (~> 3.0, >= 3.0.4)
request_store (1.3.2)
responders (1.1.2)
railties (>= 3.2, < 4.2)
resque (1.27.4)
Expand Down Expand Up @@ -339,6 +349,9 @@ GEM
crass (~> 1.0.2)
nokogiri (>= 1.4.4)
nokogumbo (~> 1.4.1)
scrypt (2.1.1)
ffi-compiler (>= 0.0.2)
rake
selenium-webdriver (3.4.0)
childprocess (~> 0.5)
rubyzip (~> 1.0)
Expand Down Expand Up @@ -378,7 +391,7 @@ GEM
tilt (2.0.7)
timecop (0.8.1)
timeliness (0.3.8)
tins (1.13.2)
tins (1.13.3)
tire (0.6.2)
activemodel (>= 3.0)
activesupport
Expand All @@ -392,7 +405,8 @@ GEM
transaction_retry (1.0.2)
activerecord (>= 3.0.11)
transaction_isolation (>= 1.0.2)
tzinfo (0.3.53)
tzinfo (1.2.3)
thread_safe (~> 0.1)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.4)
Expand Down Expand Up @@ -436,7 +450,7 @@ DEPENDENCIES
addressable
akismetor
audited (~> 4.4)
authlogic (~> 3.3.0)
authlogic (~> 3.4.6)
aws-sdk
bcrypt
bullet (~> 5.0.0)
Expand Down Expand Up @@ -486,7 +500,7 @@ DEPENDENCIES
poltergeist
pry-byebug
rack-dev-mark (>= 0.7.5)
rails (= 4.0.13)
rails (= 4.1.16)
rails-observers
redis (>= 3.0)
redis-namespace
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin/admin_invitations_controller.rb
Expand Up @@ -19,7 +19,7 @@ def create
end

def invite_from_queue
InviteRequest.find(:all, order: :position, limit: invitation_params[:invite_from_queue].to_i).each do |request|
InviteRequest.order(:position).limit(invitation_params[:invite_from_queue].to_i).each do |request|
request.invite_and_remove(current_admin)
end
InviteRequest.reset_order
Expand All @@ -46,7 +46,7 @@ def find
if !invitation_params[:token].blank?
@invitation = Invitation.find_by(token: invitation_params[:token])
elsif !invitation_params[:invitee_email].blank?
@invitations = Invitation.find(:all, conditions: ['invitee_email LIKE ?', '%' + invitation_params[:invitee_email] + '%'])
@invitations = Invitation.where('invitee_email LIKE ?', "%#{invitation_params[:invitee_email]}%")
@invitation = @invitations.first if @invitations.length == 1
end
unless @user || @invitation || @invitations
Expand Down
1 change: 1 addition & 0 deletions app/controllers/admin/admin_users_controller.rb
Expand Up @@ -211,6 +211,7 @@ def notify
else
letter = "0"
end

@all_users = User.alphabetical.starting_with(letter)
@roles = Role.assignable.uniq
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/external_authors_controller.rb
Expand Up @@ -76,7 +76,7 @@ def update
end
@invitation.mark_as_redeemed if @invitation && !params[:imported_stories].blank?

if @external_author.update_attributes(external_author_params[:external_author])
if @external_author.update_attributes(external_author_params[:external_author] || {})
flash[:notice] += "Your preferences have been saved."
if @user
redirect_to user_external_authors_path(@user)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/media_controller.rb
Expand Up @@ -8,7 +8,7 @@ def index
@fandom_listing = {}
@media.each do |medium|
if medium == uncategorized
@fandom_listing[medium] = medium.children.in_use.by_type('Fandom').find(:all, :order => 'created_at DESC', :limit => 5)
@fandom_listing[medium] = medium.children.in_use.by_type('Fandom').order('created_at DESC').limit(5)
else
@fandom_listing[medium] = (logged_in? || logged_in_as_admin?) ?
# was losing the select trying to do this through the parents association
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/pseuds_controller.rb
Expand Up @@ -14,7 +14,7 @@ def load_user
# GET /pseuds.xml
def index
if @user
@pseuds = @user.pseuds.find(:all)
@pseuds = @user.pseuds
@rec_counts = Pseud.rec_counts_for_pseuds(@pseuds)
@work_counts = Pseud.work_counts_for_pseuds(@pseuds)
@page_subtitle = @user.login
Expand All @@ -40,7 +40,7 @@ def show
@fandoms = Fandom.select("tags.*, count(tags.id) as work_count").
joins(:direct_filter_taggings).
joins("INNER JOIN works ON filter_taggings.filterable_id = works.id AND filter_taggings.filterable_type = 'Work'").
group("tags.id").order("work_count DESC").
group("tags.id").
merge(Work.visible_to_all.revealed.non_anon).
merge(Work.joins("INNER JOIN creatorships ON creatorships.creation_id = works.id AND creatorships.creation_type = 'Work'
INNER JOIN pseuds ON creatorships.pseud_id = pseuds.id").where("pseuds.id = ?", @pseud.id))
Expand All @@ -51,15 +51,15 @@ def show
@fandoms = Fandom.select("tags.*, count(tags.id) as work_count").
joins(:direct_filter_taggings).
joins("INNER JOIN works ON filter_taggings.filterable_id = works.id AND filter_taggings.filterable_type = 'Work'").
group("tags.id").order("work_count DESC").
group("tags.id").
merge(Work.visible_to_registered_user.revealed.non_anon).
merge(Work.joins("INNER JOIN creatorships ON creatorships.creation_id = works.id AND creatorships.creation_type = 'Work'
INNER JOIN pseuds ON creatorships.pseud_id = pseuds.id").where("pseuds.id = ?", @pseud.id))
visible_works = @pseud.works.visible_to_registered_user
visible_series = @pseud.series.visible_to_registered_user
visible_bookmarks = @pseud.bookmarks.visible_to_registered_user
end
@fandoms = @fandoms.all # force eager loading
@fandoms = @fandoms.order('work_count DESC').load unless @fandoms.empty?
@works = visible_works.revealed.non_anon.order("revised_at DESC").limit(ArchiveConfig.NUMBER_OF_ITEMS_VISIBLE_IN_DASHBOARD)
@series = visible_series.order("updated_at DESC").limit(ArchiveConfig.NUMBER_OF_ITEMS_VISIBLE_IN_DASHBOARD)
@bookmarks = visible_bookmarks.order("updated_at DESC").limit(ArchiveConfig.NUMBER_OF_ITEMS_VISIBLE_IN_DASHBOARD)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/series_controller.rb
Expand Up @@ -47,7 +47,7 @@ def index
# GET /series/1
# GET /series/1.xml
def show
@serial_works = @series.serial_works.includes(:work).where('works.posted = ?', true).order(:position).select{ |sw| sw.work.visible(User.current_user) }
@serial_works = @series.serial_works.includes(:work).where('works.posted = ?', true).references(:works).order(:position).select{ |sw| sw.work.visible(User.current_user) }
# sets the page title with the data for the series
@page_title = @series.unrevealed? ? ts("Mystery Series") : get_page_title(@series.allfandoms.collect(&:name).join(', '), @series.anonymous? ? ts("Anonymous") : @series.allpseuds.collect(&:byline).join(', '), @series.title)
if current_user.respond_to?(:subscriptions)
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/tags_controller.rb
Expand Up @@ -223,9 +223,9 @@ def edit
@counts['External Works'] = @tag.visible_external_works_count
@counts['Taggings Count'] = @tag.taggings_count

@parents = @tag.parents.find(:all, order: :name).group_by { |tag| tag[:type] }
@parents = @tag.parents.order(:name).group_by { |tag| tag[:type] }
@parents['MetaTag'] = @tag.direct_meta_tags.by_name
@children = @tag.children.find(:all, order: :name).group_by { |tag| tag[:type] }
@children = @tag.children.order(:name).group_by { |tag| tag[:type] }
@children['SubTag'] = @tag.direct_sub_tags.by_name
@children['Merger'] = @tag.mergers.by_name

Expand Down Expand Up @@ -273,9 +273,9 @@ def update
redirect_to url_for(controller: :tags, action: :edit, id: @tag)
end
else
@parents = @tag.parents.find(:all, order: :name).group_by { |tag| tag[:type] }
@parents = @tag.parents.order(:name).group_by { |tag| tag[:type] }
@parents['MetaTag'] = @tag.direct_meta_tags.by_name
@children = @tag.children.find(:all, order: :name).group_by { |tag| tag[:type] }
@children = @tag.children.order(:name).group_by { |tag| tag[:type] }
@children['SubTag'] = @tag.direct_sub_tags.by_name
@children['Merger'] = @tag.mergers.by_name

Expand Down
10 changes: 5 additions & 5 deletions app/controllers/users_controller.rb
Expand Up @@ -61,7 +61,7 @@ def show

visible = visible_items(current_user)

@fandoms = @fandoms.all # force eager loading
@fandoms = @fandoms.order('work_count DESC').load unless @fandoms.empty?
@works = visible[:works].revealed.non_anon.order('revised_at DESC').limit(ArchiveConfig.NUMBER_OF_ITEMS_VISIBLE_IN_DASHBOARD)
@series = visible[:series].order('updated_at DESC').limit(ArchiveConfig.NUMBER_OF_ITEMS_VISIBLE_IN_DASHBOARD)
@bookmarks = visible[:bookmarks].order('updated_at DESC').limit(ArchiveConfig.NUMBER_OF_ITEMS_VISIBLE_IN_DASHBOARD)
Expand Down Expand Up @@ -254,8 +254,8 @@ def changed_email
# DELETE /users/1.xml
def destroy
@hide_dashboard = true
@works = @user.works.find(:all, conditions: { posted: true })
@sole_owned_collections = @user.collections.delete_if { |collection| !(collection.all_owners - @user.pseuds).empty? }
@works = @user.works.where(posted: true)
@sole_owned_collections = @user.collections.to_a.delete_if { |collection| !(collection.all_owners - @user.pseuds).empty? }

if @works.empty? && @sole_owned_collections.empty?
@user.wipeout_unposted_works if @user.unposted_works
Expand Down Expand Up @@ -369,7 +369,7 @@ def visible_items(current_user)
@fandoms = Fandom.select('tags.*, count(tags.id) as work_count')
.joins(:direct_filter_taggings)
.joins("INNER JOIN works ON filter_taggings.filterable_id = works.id AND filter_taggings.filterable_type = 'Work'")
.group('tags.id').order('work_count DESC')
.group('tags.id')
.merge(Work.send(visible_method).revealed.non_anon)
.merge(Work.joins("INNER JOIN creatorships ON creatorships.creation_id = works.id AND creatorships.creation_type = 'Work'
INNER JOIN pseuds ON creatorships.pseud_id = pseuds.id
Expand Down Expand Up @@ -444,7 +444,7 @@ def destroy_author
@sole_owned_collections.each(&:destroy)
end

@works = @user.works.find(:all, conditions: { posted: true })
@works = @user.works.where(posted: true)

if @works.blank?
@user.wipeout_unposted_works if @user.unposted_works
Expand Down

0 comments on commit 38f6080

Please sign in to comment.