Permalink
Browse files

Update Rails 3.2 -> Rails 4.0 APIs.

  • Loading branch information...
parndt committed Jul 25, 2012
1 parent cd80714 commit 8d52e5b4ec207a0748113e502f77d6c3d8a74bda
@@ -16,8 +16,7 @@ Dir[File.expand_path('../tasks/**/*', __FILE__)].each do |task|
end
require "refinerycms-testing"
Refinery::Testing::Railtie.load_tasks
Refinery::Testing::Railtie.load_dummy_tasks(File.dirname(__FILE__))
Refinery::Testing::Railtie.load_dummy_tasks File.dirname(__FILE__)
desc "Build gem files for all projects"
task :build => "all:build"
@@ -5,16 +5,18 @@ module Refinery
class User < Refinery::Core::BaseModel
extend FriendlyId
has_and_belongs_to_many :roles, :join_table => :refinery_roles_users
has_and_belongs_to_many :roles, join_table: :refinery_roles_users
has_many :plugins, :class_name => "UserPlugin", :order => "position ASC", :dependent => :destroy
friendly_id :username, :use => [:slugged]
has_many :plugins, -> { order('position ASC') },
class_name: "UserPlugin", dependent: :destroy
friendly_id :username, use: [:slugged]
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
if self.respond_to?(:devise)
devise :database_authenticatable, :registerable, :recoverable, :rememberable,
:trackable, :validatable, :authentication_keys => [:login]
:trackable, :validatable, authentication_keys: [:login]
end
# Setup accessible (or protected) attributes for your model
@@ -23,15 +25,15 @@ class User < Refinery::Core::BaseModel
attr_accessor :login
attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :plugins, :login, :full_name
validates :username, :presence => true, :uniqueness => true
validates :username, presence: true, uniqueness: true
before_validation :downcase_username, :strip_username
class << self
# Find user by email or username.
# https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign_in-using-their-username-or-email-address
def find_for_database_authentication(conditions)
value = conditions[authentication_keys.first]
where(["username = :value OR email = :value", { :value => value }]).first
where(["username = :value OR email = :value", { value: value }]).first
end
end
@@ -56,8 +58,10 @@ def plugins=(plugin_names)
end
plugin_names.each do |plugin_name|
plugins.create(:name => plugin_name,
:position => plugins.select(:position).map{|p| p.position.to_i}.max + 1)
if plugin_name.is_a?(String)
plugins.create name: plugin_name,
position: plugins.select(:position).map{|p| p.position.to_i}.max + 1
end
end
end
end
@@ -4,7 +4,7 @@ class CoreController < ::Refinery::AdminController
def update_plugin_positions
params[:menu].each_with_index do |plugin_name, index|
if (plugin = current_refinery_user.plugins.find_by_name(plugin_name))
plugin.update_attributes :position => index
plugin.update_attributes position: index
end
end
render :nothing => true
@@ -6,15 +6,14 @@ rescue LoadError
end
ENGINE_PATH = File.dirname(__FILE__)
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
APP_RAKEFILE = File.expand_path "../spec/dummy/Rakefile", __FILE__
if File.exists?(APP_RAKEFILE)
if File.exists? APP_RAKEFILE
load 'rails/tasks/engine.rake'
end
require "refinerycms-testing"
Refinery::Testing::Railtie.load_tasks
Refinery::Testing::Railtie.load_dummy_tasks(ENGINE_PATH)
Refinery::Testing::Railtie.load_dummy_tasks ENGINE_PATH
load File.expand_path('../tasks/testing.rake', __FILE__)
load File.expand_path('../tasks/rspec.rake', __FILE__)
@@ -284,7 +284,7 @@ def update_positions
@current_#{singular_name}.move_to_root
end
else
@current_#{singular_name}.update_column(:position, index)
@current_#{singular_name}.update_columns position: index
end
if hash['children'].present?
@@ -2,7 +2,7 @@
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.strategy = :truncation#:transaction
end
config.before do
@@ -13,9 +13,9 @@
DatabaseCleaner.clean
end
config.around(:each, :js) do |example|
DatabaseCleaner.strategy = :truncation
example.call
DatabaseCleaner.strategy = :transaction
end
# config.around(:each, :js) do |example|
# DatabaseCleaner.strategy = :truncation
# example.call
# DatabaseCleaner.strategy = :transaction
# end
end
@@ -37,7 +37,7 @@ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
load 'rails/tasks/extension.rake' if File.exists?(APP_RAKEFILE)
require "refinerycms-testing"
Refinery::Testing::Railtie.load_tasks
Refinery::Testing::Railtie.load_dummy_tasks ENGINE_PATH
</ruby>
And run the dummy application generator:
@@ -40,10 +40,9 @@ class Translation
friendly_id :custom_slug_or_title, friendly_id_options
has_many :parts,
has_many :parts, -> { order('position ASC') },
:foreign_key => :refinery_page_id,
:class_name => '::Refinery::PagePart',
:order => 'position ASC',
:inverse_of => :page,
:dependent => :destroy,
:include => ((:translations) if ::Refinery::PagePart.respond_to?(:translation_class))
@@ -203,7 +202,7 @@ def deletable?
# This ensures that they are in the correct 0,1,2,3,4... etc order.
def reposition_parts!
reload.parts.each_with_index do |part, index|
part.update_column(:position, index)
part.update_columns position: index
end
end
@@ -1,42 +1,46 @@
if Refinery::Page.where(:menu_match => "^/$").empty?
home_page = Refinery::Page.create!({:title => "Home",
:deletable => false,
:link_url => "/",
:menu_match => "^/$"})
home_page.parts.create({
:title => "Body",
:body => "<p>Welcome to our site. This is just a place holder page while we gather our content.</p>",
:position => 0
})
home_page.parts.create({
:title => "Side Body",
:body => "<p>This is another block of content over here.</p>",
:position => 1
})
if Refinery::Page.where(menu_match: "^/$").empty?
home_page = Refinery::Page.create!(
title: "Home",
deletable: false,
link_url: "/",
menu_match: "^/$"
)
home_page.parts.create(
title: "Body",
body: "<p>Welcome to our site. This is just a place holder page while we gather our content.</p>",
position: 0
)
home_page.parts.create(
title: "Side Body",
body: "<p>This is another block of content over here.</p>",
position: 1
)
home_page_position = -1
page_not_found_page = home_page.children.create(:title => "Page not found",
:menu_match => "^/404$",
:show_in_menu => false,
:deletable => false)
page_not_found_page.parts.create({
:title => "Body",
:body => "<h2>Sorry, there was a problem...</h2><p>The page you requested was not found.</p><p><a href='/'>Return to the home page</a></p>",
:position => 0
})
page_not_found_page = home_page.children.create(
title: "Page not found",
menu_match: "^/404$",
show_in_menu: false,
deletable: false
)
page_not_found_page.parts.create(
title: "Body",
body: "<h2>Sorry, there was a problem...</h2><p>The page you requested was not found.</p><p><a href='/'>Return to the home page</a></p>",
position: 0
)
if Refinery::Page.by_title("About").empty?
about_us_page = ::Refinery::Page.create(:title => "About")
about_us_page.parts.create({
:title => "Body",
:body => "<p>This is just a standard text page example. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin metus dolor, hendrerit sit amet, aliquet nec, posuere sed, purus. Nullam et velit iaculis odio sagittis placerat. Duis metus tellus, pellentesque ut, luctus id, egestas a, lorem. Praesent vitae mauris. Aliquam sed nulla. Sed id nunc vitae leo suscipit viverra. Proin at leo ut lacus consequat rhoncus. In hac habitasse platea dictumst. Nunc quis tortor sed libero hendrerit dapibus.\n\nInteger interdum purus id erat. Duis nec velit vitae dolor mattis euismod. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse pellentesque dignissim lacus. Nulla semper euismod arcu. Suspendisse egestas, erat a consectetur dapibus, felis orci cursus eros, et sollicitudin purus urna et metus. Integer eget est sed nunc euismod vestibulum. Integer nulla dui, tristique in, euismod et, interdum imperdiet, enim. Mauris at lectus. Sed egestas tortor nec mi.</p>",
:position => 0
})
about_us_page.parts.create({
:title => "Side Body",
:body => "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus fringilla nisi a elit. Duis ultricies orci ut arcu. Ut ac nibh. Duis blandit rhoncus magna. Pellentesque semper risus ut magna. Etiam pulvinar tellus eget diam. Morbi blandit. Donec pulvinar mauris at ligula. Sed pellentesque, ipsum id congue molestie, lectus risus egestas pede, ac viverra diam lacus ac urna. Aenean elit.</p>",
:position => 1
})
about_us_page = ::Refinery::Page.create title: "About"
about_us_page.parts.create(
title: "Body",
body: "<p>This is just a standard text page example. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin metus dolor, hendrerit sit amet, aliquet nec, posuere sed, purus. Nullam et velit iaculis odio sagittis placerat. Duis metus tellus, pellentesque ut, luctus id, egestas a, lorem. Praesent vitae mauris. Aliquam sed nulla. Sed id nunc vitae leo suscipit viverra. Proin at leo ut lacus consequat rhoncus. In hac habitasse platea dictumst. Nunc quis tortor sed libero hendrerit dapibus.\n\nInteger interdum purus id erat. Duis nec velit vitae dolor mattis euismod. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse pellentesque dignissim lacus. Nulla semper euismod arcu. Suspendisse egestas, erat a consectetur dapibus, felis orci cursus eros, et sollicitudin purus urna et metus. Integer eget est sed nunc euismod vestibulum. Integer nulla dui, tristique in, euismod et, interdum imperdiet, enim. Mauris at lectus. Sed egestas tortor nec mi.</p>",
position: 0
)
about_us_page.parts.create(
title: "Side Body",
body: "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus fringilla nisi a elit. Duis ultricies orci ut arcu. Ut ac nibh. Duis blandit rhoncus magna. Pellentesque semper risus ut magna. Etiam pulvinar tellus eget diam. Morbi blandit. Donec pulvinar mauris at ligula. Sed pellentesque, ipsum id congue molestie, lectus risus egestas pede, ac viverra diam lacus ac urna. Aenean elit.</p>",
position: 1
)
end
end
@@ -46,7 +50,9 @@
'page-not-found' => 'Page not found',
'about' => 'About'
}.each do |slug, title|
Refinery::Page.by_title(title).each { |page| page.update_attributes(:slug => slug) }
Refinery::Page.by_title(title).each do |page|
page.update_attributes slug: slug
end
end
end
@@ -339,8 +339,8 @@ def turn_on_slug_scoping
it 'reposition correctly' do
page.save
page.parts.first.update_column(:position, 6)
page.parts.last.update_column(:position, 4)
page.parts.first.update_columns position: 6
page.parts.last.update_columns position: 4
page.parts.first.position.should == 6
page.parts.last.position.should == 4

0 comments on commit 8d52e5b

Please sign in to comment.