Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove Rails dependencies & run specs outside Rails

  • Loading branch information...
commit a2169ca2c0c3bfa04cdb87107ef53905cddafb3e 1 parent 51bd36f
@kjvarga authored
View
25 Gemfile
@@ -2,12 +2,12 @@ source 'http://rubygems.org'
gem 'sitemap_generator', :path => './'
-gem 'rails', '2.3.8'
-gem 'mocha', '0.9.10'
+# Rails
+# gem 'rails', '2.3.8'
+# gem 'rspec-rails', '~>1.3.2', :require => 'spec/rails'
+
+gem 'builder'
gem 'rake', '>= 0.8.7'
-gem 'rspec', '1.3.1', :require => 'spec'
-gem 'rspec-rails', '~>1.3.2', :require => 'spec/rails'
-gem 'rcov'
# Simplify these dependencies
gem 'git', '1.2.5'
@@ -19,11 +19,10 @@ gem 'gemcutter', '0.6.1'
gem 'nokogiri', '1.4.4'
gem 'sqlite3-ruby', '1.3.1', :require => 'sqlite3'
-#group :test do
-# gem 'ruby-debug', '~>0.10'
-# gem 'ruby-debug-base', '~>0.10'
-#end
-# group :test do
-# gem 'ruby-debug-base19', '0.11.26'
-# gem 'ruby-debug19'
-# end
+group :test do
+ gem 'mocha', '0.9.10'
+ gem 'rcov'
+ gem 'rspec', '1.3.1', :require => 'spec'
+ gem 'ruby-debug', '0.10.3'
+ gem 'ruby-debug-base', '0.10.3'
+end
View
33 Gemfile.lock
@@ -6,16 +6,8 @@ PATH
GEM
remote: http://rubygems.org/
specs:
- actionmailer (2.3.8)
- actionpack (= 2.3.8)
- actionpack (2.3.8)
- activesupport (= 2.3.8)
- rack (~> 1.1.0)
- activerecord (2.3.8)
- activesupport (= 2.3.8)
- activeresource (2.3.8)
- activesupport (= 2.3.8)
- activesupport (2.3.8)
+ builder (3.0.0)
+ columnize (0.3.4)
gemcutter (0.6.1)
git (1.2.5)
github (0.4.5)
@@ -33,21 +25,15 @@ GEM
mocha (0.9.10)
rake
nokogiri (1.4.4)
- rack (1.1.2)
- rails (2.3.8)
- actionmailer (= 2.3.8)
- actionpack (= 2.3.8)
- activerecord (= 2.3.8)
- activeresource (= 2.3.8)
- activesupport (= 2.3.8)
- rake (>= 0.8.3)
rake (0.9.2)
rbx-require-relative (0.0.5)
rcov (0.9.9)
rspec (1.3.1)
- rspec-rails (1.3.4)
- rack (>= 1.0.0)
- rspec (~> 1.3.1)
+ ruby-debug (0.10.3)
+ columnize (>= 0.1)
+ ruby-debug-base (~> 0.10.3.0)
+ ruby-debug-base (0.10.3)
+ linecache (>= 0.3)
rubyforge (2.0.4)
json_pure (>= 1.1.7)
spruz (0.2.13)
@@ -60,16 +46,17 @@ PLATFORMS
ruby
DEPENDENCIES
+ builder
gemcutter (= 0.6.1)
git (= 1.2.5)
github (= 0.4.5)
jeweler (= 1.4.0)
mocha (= 0.9.10)
nokogiri (= 1.4.4)
- rails (= 2.3.8)
rake (>= 0.8.7)
rcov
rspec (= 1.3.1)
- rspec-rails (~> 1.3.2)
+ ruby-debug (= 0.10.3)
+ ruby-debug-base (= 0.10.3)
sitemap_generator!
sqlite3-ruby (= 1.3.1)
View
37 config/sitemap.rb
@@ -0,0 +1,37 @@
+SitemapGenerator::Sitemap.default_host = "http://www.example.com"
+SitemapGenerator::Sitemap.create(
+ :include_root => true, :include_index => true,
+ :filename => :new_sitemaps, :sitemaps_path => 'fr/') do
+
+ add('/one', :priority => 0.7, :changefreq => 'daily')
+
+ # Test a new location and filename and sitemaps host
+ group(:sitemaps_path => 'en/', :filename => :xxx,
+ :sitemaps_host => "http://newhost.com") do
+
+ add '/two'
+ add '/three'
+ end
+
+ # Test a namer
+ group(:sitemaps_namer => SitemapGenerator::SitemapNamer.new(:abc, :start => 3)) do
+ add '/four'
+ add '/five'
+ add '/six'
+ end
+
+ add '/seven'
+
+ # This should be in a file of its own
+ group(:sitemaps_host => "http://exceptional.com") do
+ add '/eight'
+ add '/nine'
+ end
+
+ add '/ten'
+
+ # This should have no effect. Already added default links.
+ group(:include_root => true, :include_index => true) {}
+
+ add "/merchant_path", :host => "https://www.merchanthost.com"
+end
View
35 lib/sitemap_generator/application.rb
@@ -8,15 +8,42 @@ def rails?
# Returns a boolean indicating whether this environment is Rails 3
#
- # @return [Boolean]
+ # @return [Boolean]
def rails3?
rails? && Rails.version.to_f >= 3
rescue
false # Rails.version defined in 2.1.0
end
-
+
def root
- Pathname.new(rails? && Rails.root || Dir.getwd)
+ Pathname.new(rails_root || Dir.getwd)
+ end
+
+ protected
+
+ # Returns the root of the Rails application,
+ # if this is running in a Rails context.
+ # Returns `nil` if no such root is defined.
+ #
+ # @return [String, nil]
+ def rails_root
+ if defined?(::Rails.root)
+ return ::Rails.root.to_s if ::Rails.root
+ raise "ERROR: Rails.root is nil!"
+ end
+ return RAILS_ROOT.to_s if defined?(RAILS_ROOT)
+ return nil
+ end
+
+ # Returns the environment of the Rails application,
+ # if this is running in a Rails context.
+ # Returns `nil` if no such environment is defined.
+ #
+ # @return [String, nil]
+ def rails_env
+ return ::Rails.env.to_s if defined?(::Rails.env)
+ return RAILS_ENV.to_s if defined?(RAILS_ENV)
+ return nil
end
end
-end
View
6 lib/sitemap_generator/builder.rb
@@ -2,9 +2,3 @@
require 'sitemap_generator/builder/sitemap_index_file'
require 'sitemap_generator/builder/sitemap_url'
require 'sitemap_generator/builder/sitemap_index_url'
-
-module SitemapGenerator
- module Builder
-
- end
-end
View
2  lib/sitemap_generator/utilities.rb
@@ -34,4 +34,4 @@ def assert_valid_keys(hash, *valid_keys)
raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty?
end
end
-end
View
83 spec/sitemap_generator/sitemap_generator_spec.rb
@@ -36,44 +36,44 @@ def with_max_links(num)
end
end
- describe "clean task" do
- before :each do
- FileUtils.touch(rails_path('public/sitemap_index.xml.gz'))
- Helpers.invoke_task('sitemap:clean')
- end
-
- it "should delete the sitemaps" do
- file_should_not_exist(rails_path('public/sitemap_index.xml.gz'))
- end
- end
-
- describe "fresh install" do
- before :each do
- delete_sitemap_file_from_rails_app
- Helpers.invoke_task('sitemap:install')
- end
-
- it "should create config/sitemap.rb" do
- file_should_exist(rails_path('config/sitemap.rb'))
- end
-
- it "should create config/sitemap.rb matching template" do
- sitemap_template = SitemapGenerator.templates.template_path(:sitemap_sample)
- files_should_be_identical(rails_path('config/sitemap.rb'), sitemap_template)
- end
- end
-
- describe "install multiple times" do
- before :each do
- copy_sitemap_file_to_rails_app(:deprecated)
- Helpers.invoke_task('sitemap:install')
- end
-
- it "should not overwrite config/sitemap.rb" do
- sitemap_file = File.join(SitemapGenerator.root, 'spec/files/sitemap.deprecated.rb')
- files_should_be_identical(sitemap_file, rails_path('config/sitemap.rb'))
- end
- end
+ # describe "clean task" do
+ # before :each do
+ # FileUtils.touch(rails_path('public/sitemap_index.xml.gz'))
+ # Helpers.invoke_task('sitemap:clean')
+ # end
+ #
+ # it "should delete the sitemaps" do
+ # file_should_not_exist(rails_path('public/sitemap_index.xml.gz'))
+ # end
+ # end
+
+ # describe "fresh install" do
+ # before :each do
+ # delete_sitemap_file_from_rails_app
+ # Helpers.invoke_task('sitemap:install')
+ # end
+ #
+ # it "should create config/sitemap.rb" do
+ # file_should_exist(rails_path('config/sitemap.rb'))
+ # end
+ #
+ # it "should create config/sitemap.rb matching template" do
+ # sitemap_template = SitemapGenerator.templates.template_path(:sitemap_sample)
+ # files_should_be_identical(rails_path('config/sitemap.rb'), sitemap_template)
+ # end
+ # end
+
+ # describe "install multiple times" do
+ # before :each do
+ # copy_sitemap_file_to_rails_app(:deprecated)
+ # Helpers.invoke_task('sitemap:install')
+ # end
+ #
+ # it "should not overwrite config/sitemap.rb" do
+ # sitemap_file = File.join(SitemapGenerator.root, 'spec/files/sitemap.deprecated.rb')
+ # files_should_be_identical(sitemap_file, rails_path('config/sitemap.rb'))
+ # end
+ # end
[:deprecated, :create].each do |extension|
describe "generate sitemap" do
@@ -253,11 +253,6 @@ def clean_sitemap_files_from_rails_app
# Better would be to just invoke the environment task and use
# the interpreter.
def execute_sitemap_config
- if Holder.executed
- SitemapGenerator::Interpreter.run
- else
- Holder.executed = true
- Helpers.invoke_task('sitemap:refresh:no_ping')
- end
+ SitemapGenerator::Interpreter.run
end
end
View
31 spec/spec_helper.rb
@@ -1,18 +1,21 @@
-sitemap_rails =
- case ENV["SITEMAP_RAILS"]
- when 'rails3'
- "mock_rails3_gem"
- when 'gem', 'plugin'
- "mock_app_#{ENV["SITEMAP_RAILS"]}"
- else
- "mock_app_gem"
- end
-
-ENV["RAILS_ENV"] ||= 'test'
-ENV['BUNDLE_GEMFILE'] = File.join(File.dirname(__FILE__), sitemap_rails, 'Gemfile')
+ENV['RAILS_ENV'] ||= 'test'
+require "bundler/setup"
-# Load the app's Rakefile so we know everything is being loaded correctly
-load(File.join(File.dirname(__FILE__), sitemap_rails, 'Rakefile'))
+# sitemap_rails =
+# case ENV["SITEMAP_RAILS"]
+# when 'rails3'
+# "mock_rails3_gem"
+# when 'gem', 'plugin'
+# "mock_app_#{ENV["SITEMAP_RAILS"]}"
+# else
+# "mock_app_gem"
+# end
+#
+# ENV["RAILS_ENV"] ||= 'test'
+# ENV['BUNDLE_GEMFILE'] = File.join(File.dirname(__FILE__), sitemap_rails, 'Gemfile')
+#
+# # Load the app's Rakefile so we know everything is being loaded correctly
+# load(File.join(File.dirname(__FILE__), sitemap_rails, 'Rakefile'))
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Please sign in to comment.
Something went wrong with that request. Please try again.