Browse files

Bump to Rails 4.

[Closes #83]
  • Loading branch information...
1 parent dba484d commit c2351185f6a73336619f07d0c162d337e591ee2d @joneslee85 joneslee85 committed Jul 21, 2013
Showing with 377 additions and 413 deletions.
  1. +4 −5 Gemfile
  2. +97 −135 Gemfile.lock
  3. +1 −1 README.textile
  4. +6 −0 app/controllers/admin/comments_controller.rb
  5. +11 −4 app/controllers/admin/posts_controller.rb
  6. +6 −11 app/controllers/admin/undo_items_controller.rb
  7. +9 −3 app/controllers/comments_controller.rb
  8. +3 −3 app/helpers/navigation_helper.rb
  9. +1 −1 app/models/comment.rb
  10. +9 −14 app/models/comment_activity.rb
  11. +1 −1 app/models/tag.rb
  12. 0 {script → bin}/cucumber
  13. 0 {script → bin}/rails
  14. +2 −11 config/application.rb
  15. +2 −3 config/environments/development.rb
  16. +1 −0 config/environments/production.rb
  17. +2 −3 config/environments/test.rb
  18. +3 −2 config/initializers/secret_token.rb
  19. +1 −1 config/routes.rb
  20. +48 −48 db/schema.rb
  21. +1 −1 features/step_definitions/admin.rb
  22. +20 −18 features/step_definitions/factories.rb
  23. +3 −3 features/step_definitions/posts.rb
  24. +8 −7 features/support/env.rb
  25. +39 −39 lib/acts_as_taggable_on_steroids/lib/acts_as_taggable.rb
  26. +10 −10 spec/controllers/admin/comments_controller_spec.rb
  27. +4 −4 spec/controllers/admin/dashboard_controller_spec.rb
  28. +7 −7 spec/controllers/admin/pages_controller_spec.rb
  29. +13 −13 spec/controllers/admin/posts_controller_spec.rb
  30. +4 −4 spec/controllers/admin/sessions_controller_spec.rb
  31. +9 −9 spec/controllers/admin/undo_items_controller_spec.rb
  32. +1 −1 spec/controllers/archives_controller_spec.rb
  33. +3 −3 spec/controllers/comments_controller_spec.rb
  34. +2 −2 spec/controllers/pages_controller_spec.rb
  35. +7 −7 spec/controllers/posts_controller_spec.rb
  36. +2 −2 spec/models/comment_activity_spec.rb
  37. +3 −3 spec/models/comment_spec.rb
  38. +7 −7 spec/models/delete_comment_undo_spec.rb
  39. +9 −9 spec/models/post_spec.rb
  40. +1 −1 spec/views/admin/comments/index.html_spec.rb
  41. +1 −1 spec/views/admin/comments/show.html_spec.rb
  42. +2 −2 spec/views/admin/dashboard/show.html_spec.rb
  43. +1 −1 spec/views/admin/pages/index.html_spec.rb
  44. +1 −1 spec/views/admin/posts/index.html_spec.rb
  45. +2 −2 spec/views/admin/sessions/new.html_spec.rb
  46. +1 −1 spec/views/archives/index.html_spec.rb
  47. +1 −1 spec/views/layouts/admin.html_spec.rb
  48. +3 −3 spec/views/layouts/application.html_spec.rb
  49. +1 −1 spec/views/layouts/login.html_spec.rb
  50. +1 −1 spec/views/pages/show.html_spec.rb
  51. +1 −1 spec/views/posts/index.atom.builder_spec.rb
  52. +1 −1 spec/views/posts/index.html_spec.rb
  53. +1 −1 spec/views/posts/show.html_spec.rb
View
9 Gemfile
@@ -1,22 +1,21 @@
source 'https://rubygems.org'
-gem 'rails', '~> 3.2.13'
+gem 'rails', '~> 4.0.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# Gems used only for assets and not required
# in production environments by default.
-group :assets do
- gem 'sass-rails', '~> 3.2.6'
-end
+gem 'sass-rails'
platforms :ruby do
gem 'sqlite3'
end
platforms :jruby do
- gem 'activerecord-jdbcsqlite3-adapter'
+ # The stable version has not yet supported Rails 4
+ gem 'activerecord-jdbcsqlite3-adapter', '1.3.0.beta2'
gem 'trinidad'
gem 'jruby-openssl'
end
View
232 Gemfile.lock
@@ -2,198 +2,160 @@ GEM
remote: https://rubygems.org/
specs:
RedCloth (4.2.9)
- RedCloth (4.2.9-java)
aaronh-chronic (0.3.9)
- actionmailer (3.2.13)
- actionpack (= 3.2.13)
+ actionmailer (4.0.0)
+ actionpack (= 4.0.0)
mail (~> 2.5.3)
- actionpack (3.2.13)
- activemodel (= 3.2.13)
- activesupport (= 3.2.13)
- builder (~> 3.0.0)
+ actionpack (4.0.0)
+ activesupport (= 4.0.0)
+ builder (~> 3.1.0)
erubis (~> 2.7.0)
- journey (~> 1.0.4)
- rack (~> 1.4.5)
- rack-cache (~> 1.2)
- rack-test (~> 0.6.1)
- sprockets (~> 2.2.1)
- activemodel (3.2.13)
- activesupport (= 3.2.13)
- builder (~> 3.0.0)
- activerecord (3.2.13)
- activemodel (= 3.2.13)
- activesupport (= 3.2.13)
- arel (~> 3.0.2)
- tzinfo (~> 0.3.29)
- activerecord-jdbc-adapter (1.2.1)
- activerecord-jdbcsqlite3-adapter (1.2.1)
- activerecord-jdbc-adapter (~> 1.2.1)
- jdbc-sqlite3 (~> 3.7.2)
- activeresource (3.2.13)
- activemodel (= 3.2.13)
- activesupport (= 3.2.13)
- activesupport (3.2.13)
- i18n (= 0.6.1)
- multi_json (~> 1.0)
- addressable (2.2.6)
- arel (3.0.2)
- bouncy-castle-java (1.5.0146.1)
- builder (3.0.4)
- capybara (1.1.2)
+ rack (~> 1.5.2)
+ rack-test (~> 0.6.2)
+ activemodel (4.0.0)
+ activesupport (= 4.0.0)
+ builder (~> 3.1.0)
+ activerecord (4.0.0)
+ activemodel (= 4.0.0)
+ activerecord-deprecated_finders (~> 1.0.2)
+ activesupport (= 4.0.0)
+ arel (~> 4.0.0)
+ activerecord-deprecated_finders (1.0.3)
+ activesupport (4.0.0)
+ i18n (~> 0.6, >= 0.6.4)
+ minitest (~> 4.2)
+ multi_json (~> 1.3)
+ thread_safe (~> 0.1)
+ tzinfo (~> 0.3.37)
+ addressable (2.3.5)
+ arel (4.0.0)
+ atomic (1.1.10)
+ builder (3.1.4)
+ capybara (2.1.0)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
- selenium-webdriver (~> 2.0)
- xpath (~> 0.1.4)
- childprocess (0.3.0)
- ffi (~> 1.0.6)
- coderay (1.0.5)
- cucumber (1.1.4)
+ xpath (~> 2.0)
+ coderay (1.0.9)
+ cucumber (1.3.5)
builder (>= 2.1.2)
- diff-lcs (>= 1.1.2)
- gherkin (~> 2.7.1)
- json (>= 1.4.6)
- term-ansicolor (>= 1.0.6)
- cucumber-rails (1.2.1)
+ diff-lcs (>= 1.1.3)
+ gherkin (~> 2.12.0)
+ multi_json (~> 1.7.5)
+ multi_test (>= 0.0.2)
+ cucumber-rails (1.3.0)
capybara (>= 1.1.2)
- cucumber (>= 1.1.3)
+ cucumber (>= 1.1.8)
nokogiri (>= 1.5.0)
- cucumber-websteps (0.9.0)
- capybara
- cucumber
+ cucumber-websteps (0.10.0)
+ capybara (>= 1.1.2)
+ cucumber (>= 1.1.1)
launchy
- database_cleaner (0.7.0)
- diff-lcs (1.1.3)
+ database_cleaner (1.0.1)
+ diff-lcs (1.2.4)
erubis (2.7.0)
exception_notification (2.5.2)
actionmailer (>= 3.0.4)
- factory_girl (2.4.2)
- activesupport
- ffi (1.0.11)
- ffi (1.0.11-java)
+ factory_girl (4.2.0)
+ activesupport (>= 3.0.0)
formtastic (2.2.1)
actionpack (>= 3.0)
- gherkin (2.7.3)
- json (>= 1.4.6)
- gherkin (2.7.3-java)
- json (>= 1.4.6)
+ gherkin (2.12.0)
+ multi_json (~> 1.3)
hike (1.2.3)
- i18n (0.6.1)
- jdbc-sqlite3 (3.7.2)
- journey (1.0.4)
- jquery-rails (2.1.1)
- railties (>= 3.1.0, < 5.0)
- thor (~> 0.14)
- jruby-openssl (0.7.4)
- bouncy-castle-java
- jruby-rack (1.1.3)
- json (1.8.0)
- json (1.8.0-java)
- launchy (2.0.5)
- addressable (~> 2.2.6)
- launchy (2.0.5-java)
- addressable (~> 2.2.6)
- ffi (~> 1.0.9)
- spoon (~> 0.0.1)
+ i18n (0.6.4)
+ jquery-rails (3.0.4)
+ railties (>= 3.0, < 5.0)
+ thor (>= 0.14, < 2.0)
+ launchy (2.3.0)
+ addressable (~> 2.3)
lesstile (1.1.0)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.23)
- multi_json (1.0.4)
- nokogiri (1.5.0)
- nokogiri (1.5.0-java)
+ minitest (4.7.5)
+ multi_json (1.7.7)
+ multi_test (0.0.2)
+ nokogiri (1.5.10)
open_id_authentication (1.1.0)
rack-openid (~> 1.3)
polyglot (0.3.3)
- rack (1.4.5)
- rack-cache (1.2)
- rack (>= 0.4)
+ rack (1.5.2)
rack-openid (1.3.1)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
- rack-ssl (1.3.3)
- rack
rack-test (0.6.2)
rack (>= 1.0)
- rails (3.2.13)
- actionmailer (= 3.2.13)
- actionpack (= 3.2.13)
- activerecord (= 3.2.13)
- activeresource (= 3.2.13)
- activesupport (= 3.2.13)
- bundler (~> 1.0)
- railties (= 3.2.13)
- railties (3.2.13)
- actionpack (= 3.2.13)
- activesupport (= 3.2.13)
- rack-ssl (~> 1.3.2)
+ rails (4.0.0)
+ actionmailer (= 4.0.0)
+ actionpack (= 4.0.0)
+ activerecord (= 4.0.0)
+ activesupport (= 4.0.0)
+ bundler (>= 1.3.0, < 2.0)
+ railties (= 4.0.0)
+ sprockets-rails (~> 2.0.0)
+ railties (4.0.0)
+ actionpack (= 4.0.0)
+ activesupport (= 4.0.0)
rake (>= 0.8.7)
- rdoc (~> 3.4)
- thor (>= 0.14.6, < 2.0)
+ thor (>= 0.18.1, < 2.0)
rake (10.1.0)
- rdoc (3.12.2)
- json (~> 1.4)
- rspec (2.8.0)
- rspec-core (~> 2.8.0)
- rspec-expectations (~> 2.8.0)
- rspec-mocks (~> 2.8.0)
- rspec-core (2.8.0)
- rspec-expectations (2.8.0)
- diff-lcs (~> 1.1.2)
- rspec-mocks (2.8.0)
- rspec-rails (2.8.1)
+ rspec (2.14.1)
+ rspec-core (~> 2.14.0)
+ rspec-expectations (~> 2.14.0)
+ rspec-mocks (~> 2.14.0)
+ rspec-core (2.14.3)
+ rspec-expectations (2.14.0)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.14.1)
+ rspec-rails (2.14.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
- rspec (~> 2.8.0)
- ruby-openid (2.1.8)
- rubyzip (0.9.5)
+ rspec-core (~> 2.14.0)
+ rspec-expectations (~> 2.14.0)
+ rspec-mocks (~> 2.14.0)
+ ruby-openid (2.2.3)
sass (3.2.9)
- sass-rails (3.2.6)
- railties (~> 3.2.0)
+ sass-rails (4.0.0)
+ railties (>= 4.0.0.beta, < 5.0)
sass (>= 3.1.10)
- tilt (~> 1.3)
- selenium-webdriver (2.17.0)
- childprocess (>= 0.2.5)
- ffi (~> 1.0.9)
- multi_json (~> 1.0.4)
- rubyzip
- spoon (0.0.1)
- sprockets (2.2.2)
+ sprockets-rails (~> 2.0.0)
+ sprockets (2.10.0)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
- sqlite3 (1.3.5)
- term-ansicolor (1.0.7)
+ sprockets-rails (2.0.0)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ sprockets (~> 2.8)
+ sqlite3 (1.3.7)
thor (0.18.1)
+ thread_safe (0.1.0)
+ atomic
tilt (1.4.1)
treetop (1.4.14)
polyglot
polyglot (>= 0.3.1)
- trinidad (1.3.2)
- jruby-rack (>= 1.1.1)
- trinidad_jars (>= 1.0.1)
- trinidad_jars (1.0.2)
tzinfo (0.3.37)
webrat (0.7.3)
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)
- will_paginate (3.0.2)
- xpath (0.1.4)
+ will_paginate (3.0.4)
+ xpath (2.0.0)
nokogiri (~> 1.3)
PLATFORMS
- java
ruby
DEPENDENCIES
RedCloth (~> 4.2.9)
aaronh-chronic
- activerecord-jdbcsqlite3-adapter
+ activerecord-jdbcsqlite3-adapter (= 1.3.0.beta2)
coderay (~> 1.0.5)
cucumber-rails
cucumber-websteps
@@ -207,11 +169,11 @@ DEPENDENCIES
nokogiri (~> 1.5.0)
open_id_authentication
rack-openid
- rails (~> 3.2.13)
+ rails (~> 4.0.0)
rspec
rspec-rails
ruby-openid
- sass-rails (~> 3.2.6)
+ sass-rails
sqlite3
trinidad
webrat
View
2 README.textile
@@ -56,7 +56,7 @@ Enki embodies much of the philosophy of SimpleLog, but does so in a style that i
h2. Compatibility
-Uses Ruby 1.9.3 or newer and Rails 3. Runs on MySQL or Postgres. Works on heroku.
+Uses Ruby 1.9.3 or newer and Rails 4. Runs on MySQL or Postgres. Works on heroku.
h2. Contributors, these guys rock
View
6 app/controllers/admin/comments_controller.rb
@@ -44,6 +44,12 @@ def destroy
end
end
+ private
+
+ def comment_params
+ params.require(:comment).permit(:author, :author_url, :author_email, :body)
+ end
+
protected
def find_comment
View
15 app/controllers/admin/posts_controller.rb
@@ -13,7 +13,7 @@ def index
end
def create
- @post = Post.new(params[:post])
+ @post = Post.new(post_params)
if @post.save
respond_to do |format|
format.html {
@@ -23,13 +23,13 @@ def create
end
else
respond_to do |format|
- format.html { render :action => 'new', :status => :unprocessable_entity }
+ format.html { render :action => 'new', :status => :unprocessable_entity }
end
end
end
def update
- if @post.update_attributes(params[:post])
+ if @post.update_attributes(post_params)
respond_to do |format|
format.html {
flash[:notice] = "Updated post '#{@post.title}'"
@@ -38,7 +38,7 @@ def update
end
else
respond_to do |format|
- format.html { render :action => 'show', :status => :unprocessable_entity }
+ format.html { render :action => 'show', :status => :unprocessable_entity }
end
end
end
@@ -83,9 +83,16 @@ def destroy
end
end
+ private
+
+ def post_params
+ params.require(:post).permit(:title, :body, :minor_edit)
+ end
+
protected
def find_post
@post = Post.find(params[:id])
end
+
end
View
17 app/controllers/admin/undo_items_controller.rb
@@ -1,9 +1,6 @@
class Admin::UndoItemsController < Admin::BaseController
def index
- @undo_items = UndoItem.find(:all,
- :order => 'created_at DESC',
- :limit => 50
- )
+ @undo_items = UndoItem.order('created_at DESC').limit(50).all
end
def undo
@@ -12,10 +9,10 @@ def undo
object = item.process!
respond_to do |format|
- format.html {
+ format.html do
flash[:notice] = item.complete_description
redirect_to(:back)
- }
+ end
format.json {
render :json => {
:message => item.complete_description,
@@ -26,13 +23,11 @@ def undo
rescue UndoFailed
msg = "Could not undo, would result in an invalid state (i.e. a comment with no post)"
respond_to do |format|
- format.html {
+ format.html do
flash[:notice] = msg
redirect_to(:back)
- }
- format.json {
- render :json => { :message => msg }
- }
+ end
+ format.json { render :json => { :message => msg } }
end
end
end
View
12 app/controllers/comments_controller.rb
@@ -15,7 +15,7 @@ def index
end
def new
- @comment = Comment.build_for_preview(params[:comment])
+ @comment = Comment.build_for_preview(comment_params)
respond_to do |format|
format.js do
@@ -26,14 +26,14 @@ def new
# TODO: Spec OpenID with cucumber and rack-my-id
def create
- @comment = Comment.new((session[:pending_comment] || params[:comment] || {}).
+ @comment = Comment.new((session[:pending_comment] || comment_params || {}).
reject {|key, value| !Comment.protected_attribute?(key) })
@comment.post = @post
session[:pending_comment] = nil
if @comment.requires_openid_authentication?
- session[:pending_comment] = params[:comment]
+ session[:pending_comment] = comment_params
authenticate_with_open_id(@comment.author,
:optional => [:nickname, :fullname, :email]
) do |result, identity_url, registration|
@@ -71,6 +71,12 @@ def create
end
end
+ private
+
+ def comment_params
+ params.require(:comment).permit(:author, :author_url, :author_email, :body)
+ end
+
protected
def find_post
View
6 app/helpers/navigation_helper.rb
@@ -3,13 +3,13 @@ def page_links_for_navigation
link = Struct.new(:name, :url)
[link.new("Home", root_path),
link.new("Archives", archives_path)] +
- Page.find(:all, :order => 'title').collect {|page| link.new(page.title, page_path(page.slug))}
+ Page.order('title').collect { |page| link.new(page.title, page_path(page.slug)) }
end
def category_links_for_navigation
link = Struct.new(:name, :url)
- @popular_tags ||= Tag.find(:all).reject {|tag| tag.taggings.empty? }.sort_by {|tag| tag.taggings.size }.reverse
- @popular_tags.collect {|tag| link.new(tag.name, posts_path(:tag => tag.name)) }
+ @popular_tags ||= Tag.all.reject { |tag| tag.taggings.empty? }.sort_by { |tag| tag.taggings.size }.reverse
+ @popular_tags.collect { |tag| link.new(tag.name, posts_path(:tag => tag.name)) }
end
def class_for_tab(tab_name, index)
View
2 app/models/comment.rb
@@ -84,7 +84,7 @@ def build_for_preview(params)
end
def find_recent(options = {})
- find(:all, {
+ all({
:limit => DEFAULT_LIMIT,
:order => 'created_at DESC'
}.merge(options))
View
23 app/models/comment_activity.rb
@@ -13,19 +13,14 @@ def most_recent_comment
comments.first
end
- class << self
- def find_recent
- Post.find(:all,
- :group => "comments.post_id, posts." + Post.column_names.join(", posts."),
- :select => 'posts.*, max(comments.created_at), comments.post_id',
- :joins => 'INNER JOIN comments ON comments.post_id = posts.id',
- :order => 'max(comments.created_at) desc',
- :limit => 5
- ).collect {|post|
- CommentActivity.new(post)
- }.sort_by {|activity|
- activity.most_recent_comment.created_at
- }.reverse
- end
+ def self.find_recent
+ Post.select('posts.*, max(comments.created_at), comments.post_id')
+ .group('comments.post_id, posts.' + Post.column_names.join(', posts.'))
+ .joins('INNER JOIN comments ON comments.post_id = posts.id')
+ .order('max(comments.created_at) desc')
+ .limit(5)
+ .collect { |post| CommentActivity.new(post) }
+ .sort_by { |activity| activity.most_recent_comment.created_at }
+ .reverse
end
end
View
2 app/models/tag.rb
@@ -20,7 +20,7 @@ class Tag < ActiveRecord::Base
# LIKE is used for cross-database case-insensitivity
def self.find_or_create_with_like_by_name(name)
- find(:first, :conditions => ["name LIKE ?", name]) || create(:name => name)
+ where('name LIKE ?', name).first || create(:name => name)
end
def ==(object)
View
0 script/cucumber → bin/cucumber
File renamed without changes.
View
0 script/rails → bin/rails
File renamed without changes.
View
13 config/application.rb
@@ -1,18 +1,9 @@
require File.expand_path('../boot', __FILE__)
-# Pick the frameworks you want:
-require "active_record/railtie"
-require "action_controller/railtie"
-require "action_mailer/railtie"
-require "active_resource/railtie"
-require "sprockets/railtie"
-# require "rails/test_unit/railtie"
+require 'rails/all'
if defined?(Bundler)
- # If you precompile assets before deploying to production, use this line
- Bundler.require(*Rails.groups(:assets => %w(development test)))
- # If you want your assets lazily compiled in production, use this line
- # Bundler.require(:default, :assets, Rails.env)
+ Bundler.require(:default, Rails.env)
end
# This configures the base path of routes for the main application.
View
5 config/environments/development.rb
@@ -6,9 +6,6 @@
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
- # Log error messages when you accidentally call methods on nil.
- config.whiny_nils = true
-
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
@@ -28,5 +25,7 @@
# Expands the lines which load the assets
config.assets.debug = true
+
+ config.eager_load = false
end
View
1 config/environments/production.rb
@@ -61,4 +61,5 @@
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
+ config.eager_load = true
end
View
5 config/environments/test.rb
@@ -11,9 +11,6 @@
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
- # Log error messages when you accidentally call methods on nil
- config.whiny_nils = true
-
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
@@ -32,4 +29,6 @@
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
+
+ config.eager_load = false
end
View
5 config/initializers/secret_token.rb
@@ -1,7 +1,7 @@
# Be sure to restart your server when you modify this file.
if Rails.env.development? || Rails.env.test?
- Enki::Application.config.secret_token = SecureRandom.hex(20)
+ Enki::Application.config.secret_key_base = SecureRandom.hex(20)
else
# Your secret key for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
@@ -11,5 +11,6 @@
# If this is an open source project, DO NOT commit your secret to source
# control. Load it from ENV or a file that is git ignored (File.read)
- Enki::Application.config.secret_token = 'paste your token here'
+ Enki::Application.config.secret_token = 'paste your token here' # To be removed in the next version of Enki
+ Enki::Application.config.secret_key_base = 'paste your token here'
end
View
2 config/routes.rb
@@ -10,7 +10,7 @@
post 'undo', :on => :member
end
- match 'health(/:action)' => 'health', :action => 'index', :as => :health
+ get 'health(/:action)' => 'health', :action => 'index', :as => :health
root :to => 'dashboard#show'
end
View
96 db/schema.rb
@@ -9,25 +9,25 @@
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
-# It's strongly recommended to check this file into your version control system.
+# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110709024316) do
+ActiveRecord::Schema.define(version: 20110709024316) do
- create_table "comments", :force => true do |t|
- t.integer "post_id", :null => false
- t.string "author", :null => false
- t.string "author_url", :null => false
- t.string "author_email", :null => false
- t.text "body", :null => false
- t.text "body_html", :null => false
+ create_table "comments", force: true do |t|
+ t.integer "post_id", null: false
+ t.string "author", null: false
+ t.string "author_url", null: false
+ t.string "author_email", null: false
+ t.text "body", null: false
+ t.text "body_html", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
- add_index "comments", ["created_at"], :name => "index_comments_on_created_at"
- add_index "comments", ["post_id"], :name => "index_comments_on_post_id"
+ add_index "comments", ["created_at"], name: "index_comments_on_created_at"
+ add_index "comments", ["post_id"], name: "index_comments_on_post_id"
- create_table "open_id_authentication_associations", :force => true do |t|
+ create_table "open_id_authentication_associations", force: true do |t|
t.integer "issued"
t.integer "lifetime"
t.string "handle"
@@ -36,74 +36,74 @@
t.binary "secret"
end
- create_table "open_id_authentication_nonces", :force => true do |t|
- t.integer "timestamp", :null => false
+ create_table "open_id_authentication_nonces", force: true do |t|
+ t.integer "timestamp", null: false
t.string "server_url"
- t.string "salt", :null => false
+ t.string "salt", null: false
end
- create_table "pages", :force => true do |t|
- t.string "title", :null => false
- t.string "slug", :null => false
- t.text "body", :null => false
- t.text "body_html", :null => false
+ create_table "pages", force: true do |t|
+ t.string "title", null: false
+ t.string "slug", null: false
+ t.text "body", null: false
+ t.text "body_html", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
- add_index "pages", ["created_at"], :name => "index_pages_on_created_at"
- add_index "pages", ["slug"], :name => "pages_slug_unique_idx"
- add_index "pages", ["title"], :name => "index_pages_on_title"
-
- create_table "posts", :force => true do |t|
- t.string "title", :null => false
- t.string "slug", :null => false
- t.text "body", :null => false
- t.text "body_html", :null => false
- t.boolean "active", :default => true, :null => false
- t.integer "approved_comments_count", :default => 0, :null => false
+ add_index "pages", ["created_at"], name: "index_pages_on_created_at"
+ add_index "pages", ["slug"], name: "pages_slug_unique_idx"
+ add_index "pages", ["title"], name: "index_pages_on_title"
+
+ create_table "posts", force: true do |t|
+ t.string "title", null: false
+ t.string "slug", null: false
+ t.text "body", null: false
+ t.text "body_html", null: false
+ t.boolean "active", default: true, null: false
+ t.integer "approved_comments_count", default: 0, null: false
t.string "cached_tag_list"
t.datetime "published_at"
t.datetime "created_at"
t.datetime "updated_at"
- t.datetime "edited_at", :null => false
+ t.datetime "edited_at", null: false
end
- add_index "posts", ["published_at"], :name => "index_posts_on_published_at"
- add_index "posts", ["slug"], :name => "altered_posts_slug_unique_idx"
+ add_index "posts", ["published_at"], name: "index_posts_on_published_at"
+ add_index "posts", ["slug"], name: "posts_slug_unique_idx"
- create_table "sessions", :force => true do |t|
- t.string "session_id", :null => false
+ create_table "sessions", force: true do |t|
+ t.string "session_id", null: false
t.text "data"
t.datetime "created_at"
t.datetime "updated_at"
end
- add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
- add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
+ add_index "sessions", ["session_id"], name: "index_sessions_on_session_id"
+ add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at"
- create_table "taggings", :force => true do |t|
+ create_table "taggings", force: true do |t|
t.integer "tag_id"
t.integer "taggable_id"
t.datetime "created_at"
end
- add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
- add_index "taggings", ["taggable_id"], :name => "index_taggings_on_taggable_id_and_taggable_type"
+ add_index "taggings", ["tag_id"], name: "index_taggings_on_tag_id"
+ add_index "taggings", ["taggable_id"], name: "index_taggings_on_taggable_id_and_taggable_type"
- create_table "tags", :force => true do |t|
+ create_table "tags", force: true do |t|
t.string "name"
- t.integer "taggings_count", :default => 0, :null => false
+ t.integer "taggings_count", default: 0, null: false
end
- add_index "tags", ["name"], :name => "index_tags_on_name"
+ add_index "tags", ["name"], name: "index_tags_on_name"
- create_table "undo_items", :force => true do |t|
- t.string "type", :null => false
- t.datetime "created_at", :null => false
+ create_table "undo_items", force: true do |t|
+ t.string "type", null: false
+ t.datetime "created_at", null: false
t.text "data"
end
- add_index "undo_items", ["created_at"], :name => "index_undo_items_on_created_at"
+ add_index "undo_items", ["created_at"], name: "index_undo_items_on_created_at"
end
View
2 features/step_definitions/admin.rb
@@ -17,7 +17,7 @@
Given /^the following comments? exists:$/ do |comment_table|
comment_table.hashes.each do |hash|
- Factory(:comment, hash)
+ FactoryGirl.create(:comment, hash)
end
end
View
38 features/step_definitions/factories.rb
@@ -1,23 +1,25 @@
require 'factory_girl'
-Factory.define(:tag) do |a|
- a.name 'Tag'
-end
+FactoryGirl.define do
+ factory :tag do
+ name 'Tag'
+ end
-Factory.define(:post) do |a|
- a.title 'A post'
- a.slug 'a-post'
- a.body 'This is a post'
+ factory :post do
+ title 'A post'
+ slug 'a-post'
+ body 'This is a post'
- a.published_at 1.day.ago
- a.created_at 1.day.ago
- a.updated_at 1.day.ago
-end
+ published_at { 1.day.ago }
+ created_at { 1.day.ago }
+ updated_at { 1.day.ago }
+ end
-Factory.define(:comment) do |a|
- a.author 'Don Alias'
- a.author_email 'enki@enkiblog.com'
- a.author_url 'http://enkiblog.com'
- a.body 'I find this article thought provoking'
- a.association :post
-end
+ factory :comment do
+ author 'Don Alias'
+ author_email 'enki@enkiblog.com'
+ author_url 'http://enkiblog.com'
+ body 'I find this article thought provoking'
+ association :post
+ end
+end
View
6 features/step_definitions/posts.rb
@@ -1,11 +1,11 @@
Given /there is at least one post tagged "([\w\s]+)"/ do |tag_name|
- Factory(:post, :tags => [Factory(:tag, :name => tag_name)])
+ FactoryGirl.create(:post, :tags => [FactoryGirl.create(:tag, :name => tag_name)])
end
Given /there is at least one post titled "([\w\s]+)"/ do |title|
- Factory(:post, :title => title)
+ FactoryGirl.create(:post, :title => title)
end
Given /a post with comments exists/ do
- Factory(:post, :comments => [Factory(:comment), Factory(:comment)])
+ FactoryGirl.create(:post, :comments => [FactoryGirl.create(:comment), FactoryGirl.create(:comment)])
end
View
15 features/support/env.rb
@@ -1,11 +1,9 @@
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
-# It is recommended to regenerate this file in the future when you upgrade to a
-# newer version of cucumber-rails. Consider adding your own code to a new file
+# It is recommended to regenerate this file in the future when you upgrade to a
+# newer version of cucumber-rails. Consider adding your own code to a new file
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.
-ENV["RAILS_ENV"] = "test"
-
require 'cucumber/rails'
require 'capybara/rspec'
@@ -16,8 +14,8 @@
Capybara.default_selector = :css
# By default, any exception happening in your Rails application will bubble up
-# to Cucumber so that your scenario will fail. This is a different from how
-# your application behaves in the production environment, where an error page will
+# to Cucumber so that your scenario will fail. This is a different from how
+# your application behaves in the production environment, where an error page will
# be rendered instead.
#
# Sometimes we want to override this default behaviour and allow Rails to rescue
@@ -44,7 +42,10 @@
# See the DatabaseCleaner documentation for details. Example:
#
# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
-# DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}
+# # { :except => [:widgets] } may not do what you expect here
+# # as tCucumber::Rails::Database.javascript_strategy overrides
+# # this setting.
+# DatabaseCleaner.strategy = :truncation
# end
#
# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
View
78 lib/acts_as_taggable_on_steroids/lib/acts_as_taggable.rb
@@ -4,33 +4,33 @@ module Taggable #:nodoc:
def self.included(base)
base.extend(ClassMethods)
end
-
+
module ClassMethods
def acts_as_taggable
- has_many :taggings, :dependent => :destroy, :include => :tag, :foreign_key => 'taggable_id' # :as => :taggable
+ has_many :taggings, :dependent => :destroy, :foreign_key => 'taggable_id' # :as => :taggable, #:include => :tag,
has_many :tags, :through => :taggings
-
+
before_save :save_cached_tag_list
after_save :save_tags
-
+
include ActiveRecord::Acts::Taggable::InstanceMethods
extend ActiveRecord::Acts::Taggable::SingletonMethods
-
+
alias_method_chain :reload, :tag_list
end
-
+
def cached_tag_list_column_name
"cached_tag_list"
end
-
+
def set_cached_tag_list_column_name(value = nil, &block)
define_attr_method :cached_tag_list_column_name, value, &block
end
end
-
+
module SingletonMethods
# Pass either a tag string, or an array of strings or tags
- #
+ #
# Options:
# :exclude - Find models that are not tagged with the given tags
# :match_all - Find models that match all of the given tags, not just one
@@ -39,18 +39,18 @@ def find_tagged_with(*args)
options = find_options_for_find_tagged_with(*args)
options.blank? ? [] : find(:all, options)
end
-
+
def find_options_for_find_tagged_with(tags, options = {})
tags = tags.is_a?(Array) ? TagList.new(tags.map(&:to_s)) : TagList.from(tags)
options = options.dup
-
+
return {} if tags.empty?
-
+
conditions = []
conditions << sanitize_sql(options.delete(:conditions)) if options[:conditions]
-
+
taggings_alias, tags_alias = "#{table_name}_taggings", "#{table_name}_tags"
-
+
if options.delete(:exclude)
conditions << <<-END
#{table_name}.id NOT IN
@@ -70,16 +70,16 @@ def find_options_for_find_tagged_with(tags, options = {})
conditions << tags_condition(tags, tags_alias)
end
end
-
+
{ :select => "DISTINCT #{table_name}.*",
:joins => "INNER JOIN #{Tagging.table_name} #{taggings_alias} ON #{taggings_alias}.taggable_id = #{table_name}.#{primary_key} " +
"INNER JOIN #{Tag.table_name} #{tags_alias} ON #{tags_alias}.id = #{taggings_alias}.tag_id",
:conditions => conditions.join(" AND ")
}.reverse_merge!(options)
end
-
+
# Calculate the tag counts for all tags.
- #
+ #
# Options:
# :start_at - Restrict the tags to those created after a certain time
# :end_at - Restrict the tags to those created before a certain time
@@ -91,99 +91,99 @@ def find_options_for_find_tagged_with(tags, options = {})
def tag_counts(options = {})
Tag.find(:all, find_options_for_tag_counts(options))
end
-
+
def find_options_for_tag_counts(options = {})
options.assert_valid_keys :start_at, :end_at, :conditions, :at_least, :at_most, :order, :limit
options = options.dup
-
+
scope = scope(:find)
start_at = sanitize_sql(["#{Tagging.table_name}.created_at >= ?", options.delete(:start_at)]) if options[:start_at]
end_at = sanitize_sql(["#{Tagging.table_name}.created_at <= ?", options.delete(:end_at)]) if options[:end_at]
-
+
conditions = [
options.delete(:conditions),
scope && scope[:conditions],
start_at,
end_at
]
-
- conditions << type_condition unless descends_from_active_record?
+
+ conditions << type_condition unless descends_from_active_record?
conditions.compact!
conditions = conditions.join(' AND ')
-
+
joins = ["INNER JOIN #{Tagging.table_name} ON #{Tag.table_name}.id = #{Tagging.table_name}.tag_id"]
joins << "INNER JOIN #{table_name} ON #{table_name}.#{primary_key} = #{Tagging.table_name}.taggable_id"
joins << scope[:joins] if scope && scope[:joins]
-
+
at_least = sanitize_sql(['COUNT(*) >= ?', options.delete(:at_least)]) if options[:at_least]
at_most = sanitize_sql(['COUNT(*) <= ?', options.delete(:at_most)]) if options[:at_most]
having = [at_least, at_most].compact.join(' AND ')
group_by = "#{Tag.table_name}.id, #{Tag.table_name}.name HAVING COUNT(*) > 0"
group_by << " AND #{having}" unless having.blank?
-
- { :select => "#{Tag.table_name}.id, #{Tag.table_name}.name, COUNT(*) AS count",
+
+ { :select => "#{Tag.table_name}.id, #{Tag.table_name}.name, COUNT(*) AS count",
:joins => joins.join(" "),
:conditions => conditions,
:group => group_by
}.reverse_merge!(options)
end
-
+
def caching_tag_list?
column_names.include?(cached_tag_list_column_name)
end
-
+
private
def tags_condition(tags, table_name = Tag.table_name)
condition = tags.map { |t| sanitize_sql(["#{table_name}.name LIKE ?", t]) }.join(" OR ")
"(" + condition + ")"
end
end
-
+
module InstanceMethods
def tag_list
return @tag_list if @tag_list
-
+
if self.class.caching_tag_list? and !(cached_value = send(self.class.cached_tag_list_column_name)).nil?
@tag_list = TagList.from(cached_value)
else
@tag_list = TagList.new(*tags.map(&:name))
end
end
-
+
def tag_list=(value)
@tag_list = TagList.from(value)
end
-
+
def save_cached_tag_list
if self.class.caching_tag_list?
self[self.class.cached_tag_list_column_name] = tag_list.to_s
end
end
-
+
def save_tags
return unless @tag_list
-
+
new_tag_names = @tag_list - tags.map(&:name)
old_taggings = taggings.reject { |tagging| @tag_list.include?(tagging.tag.name) }
-
+
self.class.transaction do
old_taggings.each {|tag| taggings.destroy(tag)}
-
+
new_tag_names.each do |new_tag_name|
tags << Tag.find_or_create_with_like_by_name(new_tag_name)
end
end
-
+
true
end
-
+
# Calculate the tag counts for the tags used by this model.
#
# The possible options are the same as the tag_counts class method, excluding :conditions.
def tag_counts(options = {})
self.class.tag_counts({ :conditions => self.class.send(:tags_condition, tag_list) }.reverse_merge!(options))
end
-
+
def reload_with_tag_list(*args) #:nodoc:
@tag_list = nil
reload_without_tag_list(*args)
View
20 spec/controllers/admin/comments_controller_spec.rb
@@ -5,7 +5,7 @@
describe 'handling GET to index' do
before(:each) do
@posts = [mock_model(Comment), mock_model(Comment)]
- Comment.stub!(:paginate).and_return(@comments)
+ Comment.stub(:paginate).and_return(@comments)
session[:logged_in] = true
get :index
end
@@ -18,7 +18,7 @@
describe 'handling GET to show' do
before(:each) do
@comment = Comment.new
- Comment.stub!(:find).and_return(@comment)
+ Comment.stub(:find).and_return(@comment)
session[:logged_in] = true
get :show, :id => 1
end
@@ -31,8 +31,8 @@
describe 'handling PUT to update with valid attributes' do
before(:each) do
@comment = mock_model(Comment, :author => 'Don Alias')
- @comment.stub!(:update_attributes).and_return(true)
- Comment.stub!(:find).and_return(@comment)
+ @comment.stub(:update_attributes).and_return(true)
+ Comment.stub(:find).and_return(@comment)
@attributes = {'body' => 'a comment'}
end
@@ -62,8 +62,8 @@ def do_put
describe 'handling PUT to update with invalid attributes' do
before(:each) do
@comment = mock_model(Comment, :author => 'Don Alias')
- @comment.stub!(:update_attributes).and_return(false)
- Comment.stub!(:find).and_return(@comment)
+ @comment.stub(:update_attributes).and_return(false)
+ Comment.stub(:find).and_return(@comment)
@attributes = {:body => ''}
end
@@ -87,8 +87,8 @@ def do_put
describe 'handling DELETE to destroy' do
before(:each) do
@comment = Comment.new
- @comment.stub!(:destroy)
- Comment.stub!(:find).and_return(@comment)
+ @comment.stub(:destroy)
+ Comment.stub(:find).and_return(@comment)
end
def do_delete
@@ -111,8 +111,8 @@ def do_delete
describe 'handling DELETE to destroy, JSON request' do
before(:each) do
@comment = Comment.new(:author => 'xavier')
- @comment.stub!(:destroy_with_undo).and_return(mock_model(UndoItem, :description => 'hello'))
- Comment.stub!(:find).and_return(@comment)
+ @comment.stub(:destroy_with_undo).and_return(mock_model(UndoItem, :description => 'hello'))
+ Comment.stub(:find).and_return(@comment)
end
def do_delete
View
8 spec/controllers/admin/dashboard_controller_spec.rb
@@ -4,11 +4,11 @@
describe 'handling GET to show' do
before(:each) do
@posts = [mock_model(Post), mock_model(Post)]
- @comment_activity = [mock("comment-1"), mock("comment-2")]
- Post.stub!(:find_recent).and_return(@posts)
- Stats.stub!(:new).and_return(@stats = Struct.new(:post_count, :comment_count, :tag_count).new(3,2,1))
+ @comment_activity = [double("comment-1"), double("comment-2")]
+ Post.stub(:find_recent).and_return(@posts)
+ Stats.stub(:new).and_return(@stats = Struct.new(:post_count, :comment_count, :tag_count).new(3,2,1))
- CommentActivity.stub!(:find_recent).and_return(@comment_activity)
+ CommentActivity.stub(:find_recent).and_return(@comment_activity)
session[:logged_in] = true
get :show
View
14 spec/controllers/admin/pages_controller_spec.rb
@@ -4,7 +4,7 @@
describe 'handling GET to index' do
before(:each) do
@pages = [mock_model(Page), mock_model(Page)]
- Page.stub!(:paginate).and_return(@pages)
+ Page.stub(:paginate).and_return(@pages)
session[:logged_in] = true
get :index
end
@@ -25,7 +25,7 @@
describe 'handling GET to show' do
before(:each) do
@page = mock_model(Page)
- Page.stub!(:find).and_return(@page)
+ Page.stub(:find).and_return(@page)
session[:logged_in] = true
get :show, :id => 1
end
@@ -46,7 +46,7 @@
describe 'handling GET to new' do
before(:each) do
@page = mock_model(Page)
- Page.stub!(:new).and_return(@page)
+ Page.stub(:new).and_return(@page)
session[:logged_in] = true
get :new
end
@@ -58,8 +58,8 @@
describe 'handling PUT to update with valid attributes' do
before(:each) do
@page = mock_model(Page, :title => 'A page')
- @page.stub!(:update_attributes).and_return(true)
- Page.stub!(:find).and_return(@page)
+ @page.stub(:update_attributes).and_return(true)
+ Page.stub(:find).and_return(@page)
end
def do_put
@@ -91,8 +91,8 @@ def do_put
describe 'handling PUT to update with invalid attributes' do
before(:each) do
@page = mock_model(Page)
- @page.stub!(:update_attributes).and_return(false)
- Page.stub!(:find).and_return(@page)
+ @page.stub(:update_attributes).and_return(false)
+ Page.stub(:find).and_return(@page)
end
def do_put
View
26 spec/controllers/admin/posts_controller_spec.rb
@@ -4,7 +4,7 @@
describe 'handling GET to index' do
before(:each) do
@posts = [mock_model(Post), mock_model(Post)]
- Post.stub!(:paginate).and_return(@posts)
+ Post.stub(:paginate).and_return(@posts)
session[:logged_in] = true
get :index
end
@@ -25,7 +25,7 @@
describe 'handling GET to show' do
before(:each) do
@post = mock_model(Post)
- Post.stub!(:find).and_return(@post)
+ Post.stub(:find).and_return(@post)
session[:logged_in] = true
get :show, :id => 1
end
@@ -46,7 +46,7 @@
describe 'handling GET to new' do
before(:each) do
@post = mock_model(Post)
- Post.stub!(:new).and_return(@post)
+ Post.stub(:new).and_return(@post)
session[:logged_in] = true
get :new
end
@@ -58,8 +58,8 @@
describe 'handling PUT to update with valid attributes' do
before(:each) do
@post = mock_model(Post, :title => 'A post')
- @post.stub!(:update_attributes).and_return(true)
- Post.stub!(:find).and_return(@post)
+ @post.stub(:update_attributes).and_return(true)
+ Post.stub(:find).and_return(@post)
end
def do_put
@@ -71,7 +71,7 @@ def do_put
published_at = Time.now
@post.should_receive(:update_attributes).with(valid_post_attributes)
- Time.stub!(:now).and_return(published_at)
+ Time.stub(:now).and_return(published_at)
do_put
end
@@ -85,13 +85,13 @@ def do_put
describe 'handling PUT to update with invalid attributes' do
before(:each) do
@post = mock_model(Post)
- @post.stub!(:update_attributes).and_return(false)
- Post.stub!(:find).and_return(@post)
+ @post.stub(:update_attributes).and_return(false)
+ Post.stub(:find).and_return(@post)
end
def do_put
session[:logged_in] = true
- put :update, :id => 1, :post => {}
+ put :update, :id => 1, :post => valid_post_attributes
end
it 'renders show' do
@@ -123,8 +123,8 @@ def valid_post_attributes
describe 'handling DELETE to destroy' do
before(:each) do
@post = Post.new
- @post.stub!(:destroy_with_undo)
- Post.stub!(:find).and_return(@post)
+ @post.stub(:destroy_with_undo)
+ Post.stub(:find).and_return(@post)
end
def do_delete
@@ -147,8 +147,8 @@ def do_delete
describe 'handling DELETE to destroy, JSON request' do
before(:each) do
@post = Post.new(:title => 'A post')
- @post.stub!(:destroy_with_undo).and_return(mock_model(UndoItem, :description => 'hello'))
- Post.stub!(:find).and_return(@post)
+ @post.stub(:destroy_with_undo).and_return(mock_model(UndoItem, :description => 'hello'))
+ Post.stub(:find).and_return(@post)
end
def do_delete
View
8 spec/controllers/admin/sessions_controller_spec.rb
@@ -40,7 +40,7 @@
describe '#allow_login_bypass? when RAILS_ENV == production' do
it 'returns false' do
- ::Rails.stub!(:env).and_return('production')
+ ::Rails.stub(:env).and_return('production')
@controller.send(:allow_login_bypass?).should == false
end
end
@@ -74,8 +74,8 @@
end
def stub_open_id_authenticate(url, status_code, return_value)
- status = mock("Result", :successful? => status_code == :successful, :message => '')
- @controller.stub!(:enki_config).and_return(mock("enki_config", :author_open_ids => [
+ status = double("Result", :successful? => status_code == :successful, :message => '')
+ @controller.stub(:enki_config).and_return(double("enki_config", :author_open_ids => [
"http://enkiblog.com",
"http://secondaryopenid.com"
].collect {|uri| URI.parse(uri)}
@@ -138,7 +138,7 @@ def stub_open_id_authenticate(url, status_code, return_value)
end
describe "with bypass login selected but login bypassing disabled" do
before do
- @controller.stub!(:allow_login_bypass?).and_return(false)
+ @controller.stub(:allow_login_bypass?).and_return(false)
post :create, :openid_url => "", :bypass_login => "1"
end
it_should_behave_like "not logged in"
View
18 spec/controllers/admin/undo_items_controller_spec.rb
@@ -4,7 +4,7 @@
describe 'handling GET to index' do
before(:each) do
@undo_items = [mock_model(UndoItem)]
- UndoItem.stub!(:find).and_return(@undo_items)
+ UndoItem.stub_chain(:order, :limit, :all).and_return(@undo_items)
session[:logged_in] = true
get :index
end
@@ -17,8 +17,8 @@
describe 'handling POST to undo' do
before do
@item = mock_model(UndoItem, :complete_description => "hello")
- @item.stub!(:process!)
- UndoItem.stub!(:find).and_return(@item)
+ @item.stub(:process!)
+ UndoItem.stub(:find).and_return(@item)
end
def do_post
@@ -35,8 +35,8 @@ def do_post
describe 'handling POST to undo accepting JSON' do
before do
@item = mock_model(UndoItem, :complete_description => "hello")
- @item.stub!(:process!).and_return(Post.new)
- UndoItem.stub!(:find).and_return(@item)
+ @item.stub(:process!).and_return(Post.new)
+ UndoItem.stub(:find).and_return(@item)
end
def do_post
@@ -52,8 +52,8 @@ def do_post
describe 'handling POST to undo with invalid undo item' do
before do
@item = mock_model(UndoItem)
- @item.stub!(:process!).and_raise(UndoFailed)
- UndoItem.stub!(:find).and_return(@item)
+ @item.stub(:process!).and_raise(UndoFailed)
+ UndoItem.stub(:find).and_return(@item)
end
def do_post
@@ -69,8 +69,8 @@ def do_post
describe 'handling POST to undo with invalid undo item accepting JSON' do
before do
@item = mock_model(UndoItem)
- @item.stub!(:process!).and_raise(UndoFailed)
- UndoItem.stub!(:find).and_return(@item)
+ @item.stub(:process!).and_raise(UndoFailed)
+ UndoItem.stub(:find).and_return(@item)
end
def do_post
View
2 spec/controllers/archives_controller_spec.rb
@@ -5,7 +5,7 @@
before(:each) do
month = Struct.new(:date, :posts)
@months = [month.new(1.month.ago.utc.beginning_of_month, [mock_model(Post)])]
- Post.stub!(:find_all_grouped_by_month).and_return(@months)
+ Post.stub(:find_all_grouped_by_month).and_return(@months)
end
def do_get
View
6 spec/controllers/comments_controller_spec.rb
@@ -8,7 +8,7 @@
:published_at => 1.year.ago,
:slug => 'a-post'
)
- Post.stub!(:find_by_permalink).and_return(@mock_post)
+ Post.stub(:find_by_permalink).and_return(@mock_post)
get :index, :year => '2007', :month => '01', :day => '01', :slug => 'a-post'
response.should be_redirect
response.should redirect_to(post_path(@mock_post))
@@ -55,9 +55,9 @@ def mock_post!
:slug => 'a-post',
:day => '01'
}.each_pair do |attribute, value|
- @mock_post.stub!(attribute).and_return(value)
+ @mock_post.stub(attribute).and_return(value)
end
- Post.stub!(:find_by_permalink).and_return(@mock_post)
+ Post.stub(:find_by_permalink).and_return(@mock_post)
@mock_post
end
View
4 spec/controllers/pages_controller_spec.rb
@@ -4,7 +4,7 @@
describe 'handling GET for a single post' do
before(:each) do
@page = mock_model(Page)
- Page.stub!(:find_by_slug).and_return(@page)
+ Page.stub(:find_by_slug).and_return(@page)
end
def do_get
@@ -34,7 +34,7 @@ def do_get
describe 'handling GET with invalid page' do
it 'raises a RecordNotFound error' do
- Page.stub!(:find_by_slug).and_return(nil)
+ Page.stub(:find_by_slug).and_return(nil)
lambda {
get :show, :id => 'a-page'
}.should raise_error(ActiveRecord::RecordNotFound)
View
14 spec/controllers/posts_controller_spec.rb
@@ -27,7 +27,7 @@
describe 'handling GET to index'do
before(:each) do
@posts = [mock_model(Post)]
- Post.stub!(:find_recent).and_return(@posts)
+ Post.stub(:find_recent).and_return(@posts)
end
def do_get
@@ -45,7 +45,7 @@ def do_get
describe 'handling GET to index with tag'do
before(:each) do
@posts = [mock_model(Post)]
- Post.stub!(:find_recent).and_return(@posts)
+ Post.stub(:find_recent).and_return(@posts)
end
def do_get
@@ -78,7 +78,7 @@ def do_get
# means it is possible for a tag to exist (and show up in the navigation)
# without having any public posts. If that issue is ever fixed, this
# behaviour should revert to 404ing.
- Post.stub!(:find_recent).and_return([])
+ Post.stub(:find_recent).and_return([])
get :index, :tag => 'bogus'
assigns(:posts).should be_empty
end
@@ -87,7 +87,7 @@ def do_get
describe 'handling GET to /posts.atom'do
before(:each) do
@posts = [mock_model(Post)]
- Post.stub!(:find_recent).and_return(@posts)
+ Post.stub(:find_recent).and_return(@posts)
end
def do_get
@@ -107,7 +107,7 @@ def do_get
describe 'handling GET to /posts.atom with tag'do
before(:each) do
@posts = [mock_model(Post)]
- Post.stub!(:find_recent).and_return(@posts)
+ Post.stub(:find_recent).and_return(@posts)
end
def do_get
@@ -128,8 +128,8 @@ def do_get
before(:each) do
@post = mock_model(Post)
@comment = mock_model(Post)
- Post.stub!(:find_by_permalink).and_return(@post)
- Comment.stub!(:new).and_return(@comment)
+ Post.stub(:find_by_permalink).and_return(@post)
+ Comment.stub(:new).and_return(@comment)
end
def do_get
View
4 spec/models/comment_activity_spec.rb
@@ -43,15 +43,15 @@ def valid_comment_attributes(extra = {})
comments = []
comments.should_receive(:find_recent).with(hash_including(:limit => 5)).and_return(ret)
post = mock_model(Post)
- post.stub!(:approved_comments).and_return(comments)
+ post.stub(:approved_comments).and_return(comments)
CommentActivity.new(post).comments.should == ret
end
it 'is memoized to avoid excess hits to the DB' do
post = mock_model(Post)
activity = CommentActivity.new(post)
- post.should_receive(:approved_comments).once.and_return(mock('stub').as_null_object)
+ post.should_receive(:approved_comments).once.and_return(double('stub').as_null_object)
2.times { activity.comments }
end
end
View
6 spec/models/comment_spec.rb
@@ -120,16 +120,16 @@ def set_comment_attributes(comment, extra = {})
describe Comment, '.find_recent' do
it 'finds the most recent comments that were posted before now' do
now = Time.now
- Time.stub!(:now).and_return(now)
- Comment.should_receive(:find).with(:all, {
+ Time.stub(:now).and_return(now)
+ Comment.should_receive(:all).with({
:order => 'created_at DESC',
:limit => Comment::DEFAULT_LIMIT
}).and_return(comments = [mock_model(Comment)])
Comment.find_recent.should == comments
end
it 'allows and override of the default limit' do
- Comment.should_receive(:find).with(:all, hash_including(:limit => 999))
+ Comment.should_receive(:all).with(hash_including(:limit => 999))
Comment.find_recent(:limit => 999)
end
end
View
14 spec/models/delete_comment_undo_spec.rb
@@ -3,29 +3,29 @@
describe DeleteCommentUndo do
describe '#process!' do
it 'creates a new comment based on the attributes stored in #data' do
- Comment.stub!(:find_by_id).and_return(nil)
+ Comment.stub(:find_by_id).and_return(nil)
item = DeleteCommentUndo.new(:data => "---\nid: 1\na: b")
- item.stub!(:transaction).and_yield
- item.stub!(:destroy)
+ item.stub(:transaction).and_yield
+ item.stub(:destroy)
- Comment.should_receive(:create).with('a' => 'b').and_return(mock("comment", :new_record? => false))
+ Comment.should_receive(:create).with('a' => 'b').and_return(double("comment", :new_record? => false))
item.process!
end
end
describe '#process! with existing comment' do
it 'raises' do
- Comment.stub!(:find_by_id).and_return(Object.new)
+ Comment.stub(:find_by_id).and_return(Object.new)
lambda { DeleteCommentUndo.new(:data => "---\nid: 1").process! }.should raise_error(UndoFailed)
end
end
describe '#process! with invalid comment' do
it 'raises' do
- Comment.stub!(:find_by_id).and_return(nil)
+ Comment.stub(:find_by_id).and_return(nil)
- Comment.stub!(:create).and_return(mock("comment", :new_record? => true))
+ Comment.stub(:create).and_return(double("comment", :new_record? => true))
lambda { DeleteCommentUndo.new(:data => "---\nid: 1").process! }.should raise_error(UndoFailed)
end
end
View
18 spec/models/post_spec.rb
@@ -16,7 +16,7 @@
describe Post, ".find_recent" do
it 'finds the most recent posts that were published before now' do
now = Time.now
- Time.stub!(:now).and_return(now)
+ Time.stub(:now).and_return(now)
Post.should_receive(:find).with(:all, {
:order => 'posts.published_at DESC',
:conditions => ['published_at < ?', now],
@@ -27,7 +27,7 @@
it 'finds the most recent posts that were published before now with a tag' do
now = Time.now
- Time.stub!(:now).and_return(now)
+ Time.stub(:now).and_return(now)
Post.should_receive(:find_tagged_with).with('code', {
:order => 'posts.published_at DESC',
:conditions => ['published_at < ?', now],
@@ -38,7 +38,7 @@
it 'finds all posts grouped by month' do
now = Time.now
- Time.stub!(:now).and_return(now)
+ Time.stub(:now).and_return(now)
posts = [1, 1, 2].collect {|month| mock_model(Post, :month => month) }
Post.should_receive(:find).with(:all, {
:order => 'posts.published_at DESC',
@@ -87,10 +87,10 @@
describe 'when minor_edit is false' do
it 'sets edited_at to current time' do
now = Time.now
- Time.stub!(:now).and_return(now)
+ Time.stub(:now).and_return(now)
post = Post.new(:edited_at => 1.day.ago)
- post.stub!(:minor_edit?).and_return(false)
+ post.stub(:minor_edit?).and_return(false)
post.set_dates
post.edited_at.should == now
end
@@ -99,10 +99,10 @@
describe 'when edited_at is nil' do
it 'sets edited_at to current time' do
now = Time.now
- Time.stub!(:now).and_return(now)
+ Time.stub(:now).and_return(now)
post = Post.new
- post.stub!(:minor_edit?).and_return(true)
+ post.stub(:minor_edit?).and_return(true)
post.set_dates
post.edited_at.should == now
end
@@ -111,7 +111,7 @@
describe 'when minor_edit is true' do
it 'does not changed edited_at' do
post = Post.new(:edited_at => now = 1.day.ago)
- post.stub!(:minor_edit?).and_return(true)
+ post.stub(:minor_edit?).and_return(true)
post.set_dates
post.edited_at.should == now
end
@@ -195,7 +195,7 @@
it 'updates approved_comments_count without triggering AR callbacks' do
p = Post.new
p.id = 999
- p.stub!(:approved_comments).and_return(stub("approved_comments association", :count => 9))
+ p.stub(:approved_comments).and_return(double("approved_comments association", :count => 9))
Post.should_receive(:update_all).with(["approved_comments_count = ?", 9], ["id = ?", 999])
p.denormalize_comments_count!
end
View
2 spec/views/admin/comments/index.html_spec.rb
@@ -16,7 +16,7 @@
:published_at => Time.now
)
)]
- comments.stub!(:total_pages).and_return(1)
+ comments.stub(:total_pages).and_return(1)
assign :comments, comments
render :template => '/admin/comments/index', :formats => [:html]
end
View
2 spec/views/admin/comments/show.html_spec.rb
@@ -14,7 +14,7 @@
:created_at => Time.now
)
allow_message_expectations_on_nil
- assigns[:comment].stub!(:post).and_return(mock_model(Post,
+ assigns[:comment].stub(:post).and_return(mock_model(Post,
:title => 'A post',
:slug => 'a-post',
:published_at => Time.now
View
4 spec/views/admin/dashboard/show.html_spec.rb
@@ -2,7 +2,7 @@
describe "/admin/dashboard/show.html" do
before(:each) do
- view.stub!(:enki_config).and_return(Enki::Config.default)
+ view.stub(:enki_config).and_return(Enki::Config.default)
end
after(:each) do
@@ -16,7 +16,7 @@
:slug => 'a-post',
:approved_comments => []
)]
- assign :comment_activity, [mock("comment-activity-1",
+ assign :comment_activity, [double("comment-activity-1",
:post => mock_model(Post,
:published_at => Time.now,
:published? => true,