Skip to content

Commit

Permalink
Fix the failed specs for upgrade 3.2 to 4.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
yonggu committed Oct 11, 2014
1 parent d482303 commit 72895d4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rails/convert_dynamic_finders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

helper_method :dynamic_finder_to_hash do |prefix|
fields = fields_of_dynamic_finder(prefix)
return nil if (fields & attributes) != fields
return nil if (fields - attributes).present?

if fields.length == node.arguments.length && :hash != node.arguments.first.type
fields.length.times.map { |i|
Expand Down
65 changes: 65 additions & 0 deletions spec/rails/upgrade_3_2_to_4_0_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
end

describe 'with fakefs', fakefs: true do

let(:application_content) {'
if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
Expand Down Expand Up @@ -129,6 +130,20 @@ def change
end
end
"}
let(:schema_content) {'
ActiveRecord::Schema.define(version: 20140211112752) do
create_table "users", force: true do |t|
t.integer "account_id", index: true
t.string "login"
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "role", default: 0, null: false
t.boolean "admin", default: false, null: false
t.boolean "active", default: false, null: false
end
end
'}
let(:post_model_content) {'
class Post < ActiveRecord::Base
has_many :comments, dependent: :restrict
Expand All @@ -145,17 +160,33 @@ def active_users_by_email(email)
User.find_all_by_email_and_active(email, true)
end
def active_users_by_label(label)
User.find_all_by_label_and_active(label, true)
end
def first_active_user_by_email(email)
User.find_by_email_and_active(email, true)
end
def first_active_user_by_label(label)
User.find_by_label_and_active(label, true)
end
def last_active_user_by_email(email)
User.find_last_by_email_and_active(email, true)
end
def last_active_user_by_label(label)
User.find_last_by_label_and_active(label, true)
end
def scoped_active_user_by_email(email)
User.scoped_by_email_and_active(email, true)
end
def scoped_active_user_by_label(label)
User.scoped_by_label_and_active(email, true)
end
end
'}
let(:post_model_rewritten_content) {'
Expand All @@ -172,17 +203,33 @@ def active_users_by_email(email)
User.where(email: email, active: true)
end
def active_users_by_label(label)
User.find_all_by_label_and_active(label, true)
end
def first_active_user_by_email(email)
User.where(email: email, active: true).first
end
def first_active_user_by_label(label)
User.find_by_label_and_active(label, true)
end
def last_active_user_by_email(email)
User.where(email: email, active: true).last
end
def last_active_user_by_label(label)
User.find_last_by_label_and_active(label, true)
end
def scoped_active_user_by_email(email)
User.where(email: email, active: true)
end
def scoped_active_user_by_label(label)
User.scoped_by_label_and_active(email, true)
end
end
'}
let(:users_controller_content) {'
Expand All @@ -191,9 +238,17 @@ def new
@user = User.find_or_initialize_by_login_and_email(params[:user][:login], params[:user][:email])
end
def new
@user = User.find_or_initialize_by_label_and_email(params[:user][:label], params[:user][:email])
end
def create
@user = User.find_or_create_by_login_and_email(params[:user][:login], params[:user][:email])
end
def create
@user = User.find_or_create_by_label_and_email(params[:user][:label], params[:user][:email])
end
end
'}
let(:users_controller_rewritten_content) {'
Expand All @@ -202,9 +257,17 @@ def new
@user = User.find_or_initialize_by(login: params[:user][:login], email: params[:user][:email])
end
def new
@user = User.find_or_initialize_by_label_and_email(params[:user][:label], params[:user][:email])
end
def create
@user = User.find_or_create_by(login: params[:user][:login], email: params[:user][:email])
end
def create
@user = User.find_or_create_by_label_and_email(params[:user][:label], params[:user][:email])
end
end
'}
let(:posts_controller_content) {'
Expand Down Expand Up @@ -300,6 +363,8 @@ def constants
File.write 'config/initializers/secret_token.rb', secret_token_content
File.write 'config/routes.rb', routes_content
File.write 'db/migrate/20140101000000_change_posts.rb', migration_content
File.write 'db/schema.rb', schema_content
File.write 'app/models/post.rb', post_model_content
File.write 'app/models/post.rb', post_model_content
File.write 'app/controllers/users_controller.rb', users_controller_content
File.write 'app/controllers/posts_controller.rb', posts_controller_content
Expand Down

0 comments on commit 72895d4

Please sign in to comment.