Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 9 commits
  • 10 files changed
  • 0 commit comments
  • 1 contributor
View
1 Gemfile
@@ -67,6 +67,7 @@ group :development do
gem "annotate"
gem "rails-erd"
gem "debugger"
+ gem "quiet_assets"
gem "capistrano"
gem "capistrano_colors"
View
14 Gemfile.lock
@@ -1,9 +1,10 @@
GIT
remote: git://github.com/railsbp/rails_best_practices.git
- revision: a67d6ba359b00e9eda3940c9e3e2a8a51aff6c9a
+ revision: b3a3233e34ac6f7835134c090a947955014769b4
specs:
- rails_best_practices (1.8.0)
+ rails_best_practices (1.9.1)
activesupport
+ awesome_print
colored
erubis
i18n
@@ -247,7 +248,7 @@ GEM
mime-types (1.17.2)
mocha (0.10.4)
metaclass (~> 0.0.1)
- multi_json (1.1.0)
+ multi_json (1.3.2)
multi_xml (0.4.1)
multipart-post (1.1.5)
multiple_mailers (1.1.0)
@@ -289,7 +290,9 @@ GEM
cucumber (>= 0.8)
rake
polyglot (0.3.3)
- progressbar (0.10.0)
+ progressbar (0.11.0)
+ quiet_assets (1.0.0)
+ rails (~> 3.1)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
@@ -361,7 +364,7 @@ GEM
ffi (~> 1.0.9)
json_pure
rubyzip
- sexp_processor (3.0.10)
+ sexp_processor (3.2.0)
shoulda-matchers (1.0.0)
simple_cacheable (1.1.4)
rails (>= 3.0.0)
@@ -480,6 +483,7 @@ DEPENDENCIES
omniauth-twitter
paperclip
pickle
+ quiet_assets
rails
rails-erd
rails_admin!
View
2 app/cells/sidebar/sponsors.html.haml
@@ -5,4 +5,4 @@
- @sponsors.each do |sponsor|
%li= link_to image_tag(sponsor.image_url), sponsor_path(sponsor), :rel => "nofollow"
- else
- %p Looking for Sponsors
+ %p= link_to "Looking for Sponsors", "mailto:contact-us@rails-bestpractices.com"
View
5 config/application.rb
@@ -81,3 +81,8 @@ class Application < Rails::Application
# ObjectSpace.each_object(ActionDispatch::Session::DalliStore) { |obj| obj.reset }
end
end
+
+
+if ThinkingSphinx::Configuration.instance.address != "127.0.0.1"
+ ThinkingSphinx.remote_sphinx = true
+end
View
2 config/environments/production.rb
@@ -66,6 +66,4 @@
:sender_address => %{"Application Error" <exception.notifier@rails-bestpractices.com>},
:exception_recipients => %w(flyerhzm@rails-bestpractices.com flyerhzm@gmail.com),
:ignore_exceptions => %w(ActionView::MissingTemplate)
-
- ThinkingSphinx.remote_sphinx = true
end
View
4 config/initializers/rails_admin.rb
@@ -1,7 +1,3 @@
-ActsAsTaggableOn::Tag.class_eval do
- attr_accessible :name, :important
-end
-
module RailsAdmin
module Config
module Actions
View
19 lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb
@@ -1,19 +0,0 @@
-# encoding: utf-8
-require 'rails_best_practices/reviews/review'
-
-module RailsBestPractices
- module Plugins
- module Reviews
- class NotUseRailsRootReview < RailsBestPractices::Reviews::Review
- interesting_nodes :var_ref
- interesting_files ALL_FILES
-
- def start_var_ref(node)
- if node.to_s == "RAILS_ROOT"
- add_error "not use RAILS_ROOT"
- end
- end
- end
- end
- end
-end
View
46 lib/rails_best_practices/plugins/reviews/use_try_review.rb
@@ -0,0 +1,46 @@
+# encoding: utf-8
+require 'rails_best_practices/reviews/review'
+
+module RailsBestPractices
+ module Plugins
+ module Reviews
+ class UseTryReview < RailsBestPractices::Reviews::Review
+ interesting_nodes :ifop
+ interesting_files ALL_FILES
+
+ def start_ifop(node)
+ conditional_statement = node.conditional_statement
+ true_body = node[2]
+ second_body = node[3]
+ if assert_type?(conditional_statement, :vcall) &&
+ assert_type?(true_body, :call) &&
+ str_equal?(conditional_statement, true_body.subject) &&
+ assert_str?(second_body, "nil")
+ # user ? user.name : nil
+ add_error("use try (#{conditional_statement})")
+ elsif assert_type?(conditional_statement, :call) &&
+ assert_type?(second_body, :call) &&
+ str_equal?(conditional_statement.subject, second_body.subject) &&
+ assert_str?(conditional_statement.message, "nil?") &&
+ assert_str?(true_body, "nil")
+ # user.nil? ? nil : user.name
+ add_error("use try (#{conditional_statement.subject})")
+ end
+ end
+
+ private
+ def assert_type?(node, type)
+ type == node.sexp_type
+ end
+
+ def assert_str?(node, str)
+ str == node.to_s
+ end
+
+ def str_equal?(node1, node2)
+ node1.to_s == node2.to_s
+ end
+ end
+ end
+ end
+end
View
31 spec/rails_best_practices/plugins/reviews/not_use_rails_root_review_spec.rb
@@ -1,31 +0,0 @@
-require 'spec_helper'
-require 'rails_best_practices'
-
-describe RailsBestPractices::Plugins::Reviews::NotUseRailsRootReview do
- let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Plugins::Reviews::NotUseRailsRootReview.new) }
-
- it "should not use RAILS_ROOT" do
- content =<<-EOF
- class User
- def check
- RAILS_ROOT
- end
- end
- EOF
- runner.review('app/models/user.rb', content)
- runner.should have(1).errors
- runner.errors[0].to_s.should == "app/models/user.rb:3 - not use RAILS_ROOT"
- end
-
- it "should no not use RAILS_ROOT" do
- content =<<-EOF
- class User
- def check
- Rails.root
- end
- end
- EOF
- runner.review('app/models/user.rb', content)
- runner.should have(0).errors
- end
-end
View
50 spec/rails_best_practices/plugins/reviews/use_try_review_spec.rb
@@ -0,0 +1,50 @@
+require 'spec_helper'
+require 'rails_best_practices'
+
+module RailsBestPractices
+ module Plugins
+ module Reviews
+ describe UseTryReview do
+ let(:runner) { Core::Runner.new(:reviews => UseTryReview.new) }
+
+ it "should use try" do
+ content =<<-EOF
+ class Post
+ def author_name
+ author ? author.name : nil
+ end
+ end
+ EOF
+ runner.review('app/models/post.rb', content)
+ runner.should have(1).errors
+ runner.errors[0].to_s.should == "app/models/post.rb:3 - use try (author)"
+ end
+
+ it "should use try" do
+ content =<<-EOF
+ class Post
+ def author_name
+ author.nil? ? nil : author.name
+ end
+ end
+ EOF
+ runner.review('app/models/post.rb', content)
+ runner.should have(1).errors
+ runner.errors[0].to_s.should == "app/models/post.rb:3 - use try (author)"
+ end
+
+ it "should no use try" do
+ content =<<-EOF
+ class Post
+ def author_name
+ author.name
+ end
+ end
+ EOF
+ runner.review('app/models/post.rb', content)
+ runner.should have(0).errors
+ end
+ end
+ end
+ end
+end

No commit comments for this range

Something went wrong with that request. Please try again.