seo_checker 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. data/README.md +26 -0
  2. data/Rakefile +14 -0
  3. data/VERSION +1 -0
  4. data/bin/seo_checker +27 -0
  5. data/examples/bad_seo/app/controllers/application_controller.rb +10 -0
  6. data/examples/bad_seo/app/controllers/posts_controller.rb +85 -0
  7. data/examples/bad_seo/app/helpers/application_helper.rb +3 -0
  8. data/examples/bad_seo/app/helpers/posts_helper.rb +2 -0
  9. data/examples/bad_seo/app/models/post.rb +2 -0
  10. data/examples/bad_seo/config/boot.rb +110 -0
  11. data/examples/bad_seo/config/environment.rb +41 -0
  12. data/examples/bad_seo/config/environments/development.rb +17 -0
  13. data/examples/bad_seo/config/environments/production.rb +28 -0
  14. data/examples/bad_seo/config/initializers/backtrace_silencers.rb +7 -0
  15. data/examples/bad_seo/config/initializers/inflections.rb +10 -0
  16. data/examples/bad_seo/config/initializers/mime_types.rb +5 -0
  17. data/examples/bad_seo/config/initializers/new_rails_defaults.rb +21 -0
  18. data/examples/bad_seo/config/initializers/session_store.rb +15 -0
  19. data/examples/bad_seo/config/routes.rb +45 -0
  20. data/examples/bad_seo/db/migrate/20100228140057_create_posts.rb +14 -0
  21. data/examples/bad_seo/db/schema.rb +21 -0
  22. data/examples/bad_seo/db/seeds.rb +7 -0
  23. data/examples/bad_seo/test/functional/posts_controller_test.rb +45 -0
  24. data/examples/bad_seo/test/performance/browsing_test.rb +9 -0
  25. data/examples/bad_seo/test/test_helper.rb +38 -0
  26. data/examples/bad_seo/test/unit/helpers/posts_helper_test.rb +4 -0
  27. data/examples/bad_seo/test/unit/post_test.rb +8 -0
  28. data/lib/seo_checker.rb +111 -0
  29. metadata +82 -0
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # SEOChecker
2
+
3
+ Check your website if it is seo.
4
+
5
+ ## Checklists
6
+
7
+ - use sitemap file
8
+ - use unique title tags for each page
9
+ - ues unique descriptions for each page
10
+ - url does not use excessive keywords
11
+ - url does not have deep nesting of subdirectories
12
+
13
+ ## Usage
14
+
15
+ It is easy to use, just one line.
16
+ <code>seo_checker http://example.com/</code>
17
+
18
+ It is strongly recommand to check seo in development environment. If you want to test in production environment, you can use option <code>--batch</code> and <code>--interval</code> to make sure it does not get too crowded.
19
+
20
+ <pre><code>
21
+ Usage: seo_checker [OPTIONS] website_url
22
+ -b, --batch BATCH_SIZE get a batch size of pages
23
+ -i, --interval INTERVAL_TIME interval time between two batches
24
+ -h, --help Show this message
25
+ </code></pre>
26
+
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'jeweler'
3
+
4
+ Jeweler::Tasks.new do |gemspec|
5
+ gemspec.name = 'seo_checker'
6
+ gemspec.summary = 'seo_checker check your website if it is seo.'
7
+ gemspec.description = 'seo_checker check your website if it is seo.'
8
+ gemspec.email = 'flyerhzm@gmail.com'
9
+ gemspec.homepage = 'http://github.com/flyerhzm/seo_checker'
10
+ gemspec.authors = ['Richard Huang']
11
+ gemspec.files.exclude '.gitignore'
12
+ gemspec.executables << 'seo_checker'
13
+ end
14
+ Jeweler::GemcutterTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/seo_checker ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/seo_checker")
5
+
6
+ options = {}
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: seo_checker [OPTIONS] website_url"
9
+
10
+ opts.on('-b', '--batch BATCH_SIZE', 'get a batch size of pages') do |batch|
11
+ options[:batch_size] = batch
12
+ end
13
+
14
+ opts.on('-i', '--interval INTERVAL_TIME', 'interval time between two batches') do |interval|
15
+ options[:interval_time] = interval
16
+ end
17
+
18
+ opts.on_tail('-h', '--help', 'Show this message') do
19
+ puts opts
20
+ exit
21
+ end
22
+
23
+ opts.parse!
24
+ end
25
+
26
+ checker = SEOChecker.new(ARGV[0], options)
27
+ checker.check
@@ -0,0 +1,10 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
7
+
8
+ # Scrub sensitive parameters from your log
9
+ # filter_parameter_logging :password
10
+ end
@@ -0,0 +1,85 @@
1
+ class PostsController < ApplicationController
2
+ # GET /posts
3
+ # GET /posts.xml
4
+ def index
5
+ @posts = Post.all
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.xml { render :xml => @posts }
10
+ end
11
+ end
12
+
13
+ # GET /posts/1
14
+ # GET /posts/1.xml
15
+ def show
16
+ @post = Post.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.xml { render :xml => @post }
21
+ end
22
+ end
23
+
24
+ # GET /posts/new
25
+ # GET /posts/new.xml
26
+ def new
27
+ @post = Post.new
28
+
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.xml { render :xml => @post }
32
+ end
33
+ end
34
+
35
+ # GET /posts/1/edit
36
+ def edit
37
+ @post = Post.find(params[:id])
38
+ end
39
+
40
+ # POST /posts
41
+ # POST /posts.xml
42
+ def create
43
+ @post = Post.new(params[:post])
44
+
45
+ respond_to do |format|
46
+ if @post.save
47
+ flash[:notice] = 'Post was successfully created.'
48
+ format.html { redirect_to(@post) }
49
+ format.xml { render :xml => @post, :status => :created, :location => @post }
50
+ else
51
+ format.html { render :action => "new" }
52
+ format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
53
+ end
54
+ end
55
+ end
56
+
57
+ # PUT /posts/1
58
+ # PUT /posts/1.xml
59
+ def update
60
+ @post = Post.find(params[:id])
61
+
62
+ respond_to do |format|
63
+ if @post.update_attributes(params[:post])
64
+ flash[:notice] = 'Post was successfully updated.'
65
+ format.html { redirect_to(@post) }
66
+ format.xml { head :ok }
67
+ else
68
+ format.html { render :action => "edit" }
69
+ format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
70
+ end
71
+ end
72
+ end
73
+
74
+ # DELETE /posts/1
75
+ # DELETE /posts/1.xml
76
+ def destroy
77
+ @post = Post.find(params[:id])
78
+ @post.destroy
79
+
80
+ respond_to do |format|
81
+ format.html { redirect_to(posts_url) }
82
+ format.xml { head :ok }
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,2 @@
1
+ module PostsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class Post < ActiveRecord::Base
2
+ end
@@ -0,0 +1,110 @@
1
+ # Don't change this file!
2
+ # Configure your app in config/environment.rb and config/environments/*.rb
3
+
4
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
+
6
+ module Rails
7
+ class << self
8
+ def boot!
9
+ unless booted?
10
+ preinitialize
11
+ pick_boot.run
12
+ end
13
+ end
14
+
15
+ def booted?
16
+ defined? Rails::Initializer
17
+ end
18
+
19
+ def pick_boot
20
+ (vendor_rails? ? VendorBoot : GemBoot).new
21
+ end
22
+
23
+ def vendor_rails?
24
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
25
+ end
26
+
27
+ def preinitialize
28
+ load(preinitializer_path) if File.exist?(preinitializer_path)
29
+ end
30
+
31
+ def preinitializer_path
32
+ "#{RAILS_ROOT}/config/preinitializer.rb"
33
+ end
34
+ end
35
+
36
+ class Boot
37
+ def run
38
+ load_initializer
39
+ Rails::Initializer.run(:set_load_path)
40
+ end
41
+ end
42
+
43
+ class VendorBoot < Boot
44
+ def load_initializer
45
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
+ Rails::Initializer.run(:install_gem_spec_stubs)
47
+ Rails::GemDependency.add_frozen_gem_path
48
+ end
49
+ end
50
+
51
+ class GemBoot < Boot
52
+ def load_initializer
53
+ self.class.load_rubygems
54
+ load_rails_gem
55
+ require 'initializer'
56
+ end
57
+
58
+ def load_rails_gem
59
+ if version = self.class.gem_version
60
+ gem 'rails', version
61
+ else
62
+ gem 'rails'
63
+ end
64
+ rescue Gem::LoadError => load_error
65
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
66
+ exit 1
67
+ end
68
+
69
+ class << self
70
+ def rubygems_version
71
+ Gem::RubyGemsVersion rescue nil
72
+ end
73
+
74
+ def gem_version
75
+ if defined? RAILS_GEM_VERSION
76
+ RAILS_GEM_VERSION
77
+ elsif ENV.include?('RAILS_GEM_VERSION')
78
+ ENV['RAILS_GEM_VERSION']
79
+ else
80
+ parse_gem_version(read_environment_rb)
81
+ end
82
+ end
83
+
84
+ def load_rubygems
85
+ min_version = '1.3.2'
86
+ require 'rubygems'
87
+ unless rubygems_version >= min_version
88
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
89
+ exit 1
90
+ end
91
+
92
+ rescue LoadError
93
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
94
+ exit 1
95
+ end
96
+
97
+ def parse_gem_version(text)
98
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
99
+ end
100
+
101
+ private
102
+ def read_environment_rb
103
+ File.read("#{RAILS_ROOT}/config/environment.rb")
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ # All that for this:
110
+ Rails.boot!
@@ -0,0 +1,41 @@
1
+ # Be sure to restart your server when you modify this file
2
+
3
+ # Specifies gem version of Rails to use when vendor/rails is not present
4
+ RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
5
+
6
+ # Bootstrap the Rails environment, frameworks, and default configuration
7
+ require File.join(File.dirname(__FILE__), 'boot')
8
+
9
+ Rails::Initializer.run do |config|
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Add additional load paths for your own custom dirs
15
+ # config.load_paths += %W( #{RAILS_ROOT}/extras )
16
+
17
+ # Specify gems that this application depends on and have them installed with rake gems:install
18
+ # config.gem "bj"
19
+ # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
20
+ # config.gem "sqlite3-ruby", :lib => "sqlite3"
21
+ # config.gem "aws-s3", :lib => "aws/s3"
22
+
23
+ # Only load the plugins named here, in the order given (default is alphabetical).
24
+ # :all can be used as a placeholder for all plugins not explicitly named
25
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
26
+
27
+ # Skip frameworks you're not going to use. To use Rails without a database,
28
+ # you must remove the Active Record framework.
29
+ # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
30
+
31
+ # Activate observers that should always be running
32
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
33
+
34
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
35
+ # Run "rake -D time" for a list of tasks for finding time zone names.
36
+ config.time_zone = 'UTC'
37
+
38
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
39
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
40
+ # config.i18n.default_locale = :de
41
+ end
@@ -0,0 +1,17 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # In the development environment your application's code is reloaded on
4
+ # every request. This slows down response time but is perfect for development
5
+ # since you don't have to restart the webserver when you make code changes.
6
+ config.cache_classes = false
7
+
8
+ # Log error messages when you accidentally call methods on nil.
9
+ config.whiny_nils = true
10
+
11
+ # Show full error reports and disable caching
12
+ config.action_controller.consider_all_requests_local = true
13
+ config.action_view.debug_rjs = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
@@ -0,0 +1,28 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The production environment is meant for finished, "live" apps.
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.action_controller.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+ config.action_view.cache_template_loading = true
11
+
12
+ # See everything in the log (default is :info)
13
+ # config.log_level = :debug
14
+
15
+ # Use a different logger for distributed setups
16
+ # config.logger = SyslogLogger.new
17
+
18
+ # Use a different cache store in production
19
+ # config.cache_store = :mem_cache_store
20
+
21
+ # Enable serving of images, stylesheets, and javascripts from an asset server
22
+ # config.action_controller.asset_host = "http://assets.example.com"
23
+
24
+ # Disable delivery errors, bad email addresses will be ignored
25
+ # config.action_mailer.raise_delivery_errors = false
26
+
27
+ # Enable threaded mode
28
+ # config.threadsafe!
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying do debug a problem that might steem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,21 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # These settings change the behavior of Rails 2 apps and will be defaults
4
+ # for Rails 3. You can remove this initializer when Rails 3 is released.
5
+
6
+ if defined?(ActiveRecord)
7
+ # Include Active Record class name as root for JSON serialized output.
8
+ ActiveRecord::Base.include_root_in_json = true
9
+
10
+ # Store the full class name (including module namespace) in STI type column.
11
+ ActiveRecord::Base.store_full_sti_class = true
12
+ end
13
+
14
+ ActionController::Routing.generate_best_match = false
15
+
16
+ # Use ISO 8601 format for JSON serialized times and dates.
17
+ ActiveSupport.use_standard_json_time_format = true
18
+
19
+ # Don't escape HTML entities in JSON, leave that for the #json_escape helper.
20
+ # if you're including raw json in an HTML page.
21
+ ActiveSupport.escape_html_entities_in_json = false
@@ -0,0 +1,15 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying cookie session data integrity.
4
+ # If you change this key, all old sessions will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ ActionController::Base.session = {
8
+ :key => '_bad_seo_session',
9
+ :secret => 'da5ede0a3f96915cdc9563d8d7ca433be9e2d6280cb99c34e597fc7d2164337bec95de1538573c8e04897d6e194f3d518c6a17c0bbe79da9ec946e4c66b82f98'
10
+ }
11
+
12
+ # Use the database for sessions instead of the cookie-based default,
13
+ # which shouldn't be used to store highly confidential information
14
+ # (create the session table with "rake db:sessions:create")
15
+ # ActionController::Base.session_store = :active_record_store
@@ -0,0 +1,45 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ map.resources :posts
3
+
4
+ # The priority is based upon order of creation: first created -> highest priority.
5
+
6
+ # Sample of regular route:
7
+ # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
8
+ # Keep in mind you can assign values other than :controller and :action
9
+
10
+ # Sample of named route:
11
+ # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
12
+ # This route can be invoked with purchase_url(:id => product.id)
13
+
14
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
15
+ # map.resources :products
16
+
17
+ # Sample resource route with options:
18
+ # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
19
+
20
+ # Sample resource route with sub-resources:
21
+ # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
22
+
23
+ # Sample resource route with more complex sub-resources
24
+ # map.resources :products do |products|
25
+ # products.resources :comments
26
+ # products.resources :sales, :collection => { :recent => :get }
27
+ # end
28
+
29
+ # Sample resource route within a namespace:
30
+ # map.namespace :admin do |admin|
31
+ # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
32
+ # admin.resources :products
33
+ # end
34
+
35
+ # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
36
+ # map.root :controller => "welcome"
37
+
38
+ # See how all your routes lay out with "rake routes"
39
+
40
+ # Install the default routes as the lowest priority.
41
+ # Note: These default routes make all actions in every controller accessible via GET requests. You should
42
+ # consider removing or commenting them out if you're using named routes and resources.
43
+ map.connect ':controller/:action/:id'
44
+ map.connect ':controller/:action/:id.:format'
45
+ end
@@ -0,0 +1,14 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :posts do |t|
4
+ t.string :title
5
+ t.text :body
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :posts
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ # This file is auto-generated from the current state of the database. Instead of editing this file,
2
+ # please use the migrations feature of Active Record to incrementally modify your database, and
3
+ # then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6
+ # to create the application database on another system, you should be using db:schema:load, not running
7
+ # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
9
+ #
10
+ # It's strongly recommended to check this file into your version control system.
11
+
12
+ ActiveRecord::Schema.define(:version => 20100228140057) do
13
+
14
+ create_table "posts", :force => true do |t|
15
+ t.string "title"
16
+ t.text "body"
17
+ t.datetime "created_at"
18
+ t.datetime "updated_at"
19
+ end
20
+
21
+ end
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7
+ # Major.create(:name => 'Daley', :city => cities.first)
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+
3
+ class PostsControllerTest < ActionController::TestCase
4
+ test "should get index" do
5
+ get :index
6
+ assert_response :success
7
+ assert_not_nil assigns(:posts)
8
+ end
9
+
10
+ test "should get new" do
11
+ get :new
12
+ assert_response :success
13
+ end
14
+
15
+ test "should create post" do
16
+ assert_difference('Post.count') do
17
+ post :create, :post => { }
18
+ end
19
+
20
+ assert_redirected_to post_path(assigns(:post))
21
+ end
22
+
23
+ test "should show post" do
24
+ get :show, :id => posts(:one).to_param
25
+ assert_response :success
26
+ end
27
+
28
+ test "should get edit" do
29
+ get :edit, :id => posts(:one).to_param
30
+ assert_response :success
31
+ end
32
+
33
+ test "should update post" do
34
+ put :update, :id => posts(:one).to_param, :post => { }
35
+ assert_redirected_to post_path(assigns(:post))
36
+ end
37
+
38
+ test "should destroy post" do
39
+ assert_difference('Post.count', -1) do
40
+ delete :destroy, :id => posts(:one).to_param
41
+ end
42
+
43
+ assert_redirected_to posts_path
44
+ end
45
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionController::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
+ require 'test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Transactional fixtures accelerate your tests by wrapping each test method
7
+ # in a transaction that's rolled back on completion. This ensures that the
8
+ # test database remains unchanged so your fixtures don't have to be reloaded
9
+ # between every test method. Fewer database queries means faster tests.
10
+ #
11
+ # Read Mike Clark's excellent walkthrough at
12
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
13
+ #
14
+ # Every Active Record database supports transactions except MyISAM tables
15
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
16
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
17
+ # is recommended.
18
+ #
19
+ # The only drawback to using transactional fixtures is when you actually
20
+ # need to test transactions. Since your test is bracketed by a transaction,
21
+ # any transactions started in your code will be automatically rolled back.
22
+ self.use_transactional_fixtures = true
23
+
24
+ # Instantiated fixtures are slow, but give you @david where otherwise you
25
+ # would need people(:david). If you don't want to migrate your existing
26
+ # test cases which use the @david style and don't mind the speed hit (each
27
+ # instantiated fixtures translates to a database query per test method),
28
+ # then set this back to true.
29
+ self.use_instantiated_fixtures = false
30
+
31
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
32
+ #
33
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
34
+ # -- they do not yet inherit this setting
35
+ fixtures :all
36
+
37
+ # Add more helper methods to be used by all tests here...
38
+ end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class PostsHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class PostTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,111 @@
1
+ require 'enumerator'
2
+ require 'net/http'
3
+ require 'uri'
4
+
5
+ class SEOException < Exception
6
+ end
7
+
8
+ class SEOChecker
9
+ def initialize(url, options={})
10
+ @url = url
11
+ @locations = []
12
+ @titles = {}
13
+ @descriptions = {}
14
+ @errors = []
15
+ @batch_size = options[:batch_size].to_i
16
+ @interval_time = options[:interval_time].to_i || 0
17
+ end
18
+
19
+ def check
20
+ begin
21
+ check_sitemap
22
+ check_location
23
+
24
+ report
25
+ rescue SEOException => e
26
+ puts e.message
27
+ end
28
+ end
29
+
30
+ def check_sitemap
31
+ #TODO: allow manual sitemap file
32
+ uri = URI.parse(@url)
33
+ uri.path = '/sitemap.xml'
34
+ response = get_response(uri)
35
+ if response.is_a? Net::HTTPSuccess
36
+ @locations = response.body.scan(%r{<loc>(.*?)</loc>}).flatten
37
+ else
38
+ raise SEOException, "Error: There is no sitemap.xml."
39
+ end
40
+ end
41
+
42
+ def check_location
43
+ @batch_size ||= @locations.size
44
+ @locations.each_slice(@batch_size) do |batch_locations|
45
+ batch_locations.each do |location|
46
+ response = get_response(URI.parse(location))
47
+ if response.is_a? Net::HTTPSuccess
48
+ check_title(response, location)
49
+ check_description(response, location)
50
+ check_url(location)
51
+ else
52
+ @errors << "The page is unreachable #{location}."
53
+ end
54
+ end
55
+ sleep(@interval_time)
56
+ end
57
+ end
58
+
59
+ def report
60
+ @titles.each do |title, locations|
61
+ if locations.size > 1
62
+ @errors << "#{locations.slice(0, 5).join(', ')} #{'and ...' if locations.size > 5} have the same title '#{title}'."
63
+ end
64
+ end
65
+ @descriptions.each do |description, locations|
66
+ if locations.size > 1
67
+ @errors << "#{locations.slice(0, 5).join(', ')} #{'and ...' if locations.size > 5} have the same description '#{description}'."
68
+ end
69
+ end
70
+ puts @errors.join("\n")
71
+ end
72
+
73
+ private
74
+ def get_response(uri)
75
+ http = Net::HTTP.new(uri.host, uri.port)
76
+ request = Net::HTTP::Get.new(uri.request_uri)
77
+ request["User-Agent"] = "seo-checker"
78
+ response = http.request(request)
79
+ end
80
+
81
+ def check_title(response, location)
82
+ if response.body =~ %r{<title>(.*?)</title>}
83
+ title = $1
84
+ else
85
+ @errors << "#{location} has no title."
86
+ end
87
+ (@titles[title] ||= []) << location
88
+ end
89
+
90
+ def check_description(response, location)
91
+ if response.body =~ %r{<meta\s+name=["']description["']\s+content=["'](.*?)["']\s*/>|<meta\s+content=["'](.*?)["']\s+name=["']description["']\s*/>}
92
+ description = $1 || $2
93
+ else
94
+ @errors << "#{location} has no description."
95
+ end
96
+ (@descriptions[description] ||= []) << location
97
+ end
98
+
99
+ def check_url(location)
100
+ items = location.split('/')
101
+ if items.find { |item| item =~ /^\d+$/ } || items.last =~ /^\d+\.htm(l)?/
102
+ @errors << "#{location} should not just use ID number in URL."
103
+ end
104
+ if items.find { |item| item.split('-').size > 5 }
105
+ @errors << "#{location} use excessive keywords"
106
+ end
107
+ if items.size > 8
108
+ @errors << "#{location} has deep nesting of subdirectories"
109
+ end
110
+ end
111
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seo_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Richard Huang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-03-02 00:00:00 +08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: seo_checker check your website if it is seo.
17
+ email: flyerhzm@gmail.com
18
+ executables:
19
+ - seo_checker
20
+ - seo_checker
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - README.md
25
+ files:
26
+ - README.md
27
+ - Rakefile
28
+ - VERSION
29
+ - bin/seo_checker
30
+ - lib/seo_checker.rb
31
+ has_rdoc: true
32
+ homepage: http://github.com/flyerhzm/seo_checker
33
+ licenses: []
34
+
35
+ post_install_message:
36
+ rdoc_options:
37
+ - --charset=UTF-8
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ requirements: []
53
+
54
+ rubyforge_project:
55
+ rubygems_version: 1.3.5
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: seo_checker check your website if it is seo.
59
+ test_files:
60
+ - examples/bad_seo/config/routes.rb
61
+ - examples/bad_seo/config/initializers/backtrace_silencers.rb
62
+ - examples/bad_seo/config/initializers/new_rails_defaults.rb
63
+ - examples/bad_seo/config/initializers/session_store.rb
64
+ - examples/bad_seo/config/initializers/inflections.rb
65
+ - examples/bad_seo/config/initializers/mime_types.rb
66
+ - examples/bad_seo/config/environment.rb
67
+ - examples/bad_seo/config/boot.rb
68
+ - examples/bad_seo/config/environments/production.rb
69
+ - examples/bad_seo/config/environments/development.rb
70
+ - examples/bad_seo/test/test_helper.rb
71
+ - examples/bad_seo/test/performance/browsing_test.rb
72
+ - examples/bad_seo/test/functional/posts_controller_test.rb
73
+ - examples/bad_seo/test/unit/helpers/posts_helper_test.rb
74
+ - examples/bad_seo/test/unit/post_test.rb
75
+ - examples/bad_seo/db/migrate/20100228140057_create_posts.rb
76
+ - examples/bad_seo/db/seeds.rb
77
+ - examples/bad_seo/db/schema.rb
78
+ - examples/bad_seo/app/helpers/application_helper.rb
79
+ - examples/bad_seo/app/helpers/posts_helper.rb
80
+ - examples/bad_seo/app/models/post.rb
81
+ - examples/bad_seo/app/controllers/application_controller.rb
82
+ - examples/bad_seo/app/controllers/posts_controller.rb