bcms_sitemap 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ module TestFactory
2
+ def _create(object)
3
+ flunk object.errors.full_messages if object.new_record?
4
+ object
5
+ end
6
+
7
+ def new_search_engine(options = {})
8
+ SearchEngine.new({:name => 'Google',
9
+ :url => 'http://www.google.com/webmasters/tools/ping?sitemap=',
10
+ :enabled => true}.merge(options))
11
+ end
12
+ def create_search_engine(options = {})
13
+ _create SearchEngine.create({:name => 'Google',
14
+ :url => 'http://www.google.com/webmasters/tools/ping?sitemap=',
15
+ :enabled => true}.merge(options))
16
+ end
17
+
18
+ def create_page(options = {})
19
+ _create Page.create({:name => 'Home',
20
+ :path => '/',
21
+ :template_file_name => 'home_page.html.erb',
22
+ :hidden => false,
23
+ :published => true}.merge(options))
24
+ end
25
+
26
+ def create_news_article(options = {})
27
+ _create NewsArticle.create({:name => 'Nyhet', :body => 'i dag', :published => true, :release_date => Date.today}.merge(options))
28
+ end
29
+ end
@@ -0,0 +1,39 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
+ require 'test_help'
4
+ require 'test_factory'
5
+
6
+ class ActiveSupport::TestCase
7
+ # Transactional fixtures accelerate your tests by wrapping each test method
8
+ # in a transaction that's rolled back on completion. This ensures that the
9
+ # test database remains unchanged so your fixtures don't have to be reloaded
10
+ # between every test method. Fewer database queries means faster tests.
11
+ #
12
+ # Read Mike Clark's excellent walkthrough at
13
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
14
+ #
15
+ # Every Active Record database supports transactions except MyISAM tables
16
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
17
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
18
+ # is recommended.
19
+ #
20
+ # The only drawback to using transactional fixtures is when you actually
21
+ # need to test transactions. Since your test is bracketed by a transaction,
22
+ # any transactions started in your code will be automatically rolled back.
23
+ self.use_transactional_fixtures = true
24
+
25
+ # Instantiated fixtures are slow, but give you @david where otherwise you
26
+ # would need people(:david). If you don't want to migrate your existing
27
+ # test cases which use the @david style and don't mind the speed hit (each
28
+ # instantiated fixtures translates to a database query per test method),
29
+ # then set this back to true.
30
+ self.use_instantiated_fixtures = false
31
+
32
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
33
+ #
34
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
35
+ # -- they do not yet inherit this setting
36
+ fixtures :all
37
+
38
+ include TestFactory
39
+ end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class SitemapsHelperTest < ActionView::TestCase
4
+ end
@@ -0,0 +1,126 @@
1
+ require 'test_helper'
2
+ #require 'fileutils'
3
+ TEST_FILES_FOLDER = "#{RAILS_ROOT}/tmp/test"
4
+
5
+ class SearchEngineTest < ActiveSupport::TestCase
6
+ should_validate_presence_of :name
7
+ should_validate_uniqueness_of :name, :case_sensitive => false
8
+
9
+ context 'search_engine' do
10
+ setup do
11
+ @search_engine = create_search_engine
12
+ end
13
+ context 'validating' do
14
+ should 'require url if enabled' do
15
+ @search_engine.url = nil
16
+ assert !@search_engine.valid?
17
+ end
18
+ should 'not require url if not enabled' do
19
+ @search_engine.url = nil
20
+ @search_engine.enabled = false
21
+ assert @search_engine.valid?
22
+ end
23
+ end
24
+ should 'have signatory_folder' do
25
+ assert_equal "#{RAILS_ROOT}/public", @search_engine.signatory_folder
26
+ end
27
+ end
28
+
29
+ context 'submition' do
30
+ setup do
31
+ @search_engine = create_search_engine
32
+ Cms::SitemapSubmitter.stubs(:submit).returns(200)
33
+ flunk if @search_engine.submitted_at || @search_engine.last_status
34
+ end
35
+ should 'update sumittion time stamp after submition' do
36
+ @search_engine.submit
37
+ assert_not_nil @search_engine.submitted_at
38
+ end
39
+
40
+ should 'update last_status' do
41
+ @search_engine.submit
42
+ assert_equal 200, @search_engine.reload.last_status
43
+ end
44
+ end
45
+
46
+ def prepare_test_folder
47
+ empty_test_folder
48
+ Dir.mkdir TEST_FILES_FOLDER unless File.directory? TEST_FILES_FOLDER
49
+ end
50
+
51
+ def teardown_test_folder
52
+ empty_test_folder
53
+ Dir.delete TEST_FILES_FOLDER if File.directory? TEST_FILES_FOLDER
54
+ end
55
+
56
+ def empty_test_folder
57
+ return unless File.directory? TEST_FILES_FOLDER
58
+ Dir.glob("#{TEST_FILES_FOLDER}/*").each do |file_name|
59
+ FileUtils.rm file_name
60
+ end
61
+ end
62
+
63
+ context 'signatory files' do
64
+ setup do
65
+ prepare_test_folder
66
+ @filename = "google1111111111111.html"
67
+ @filecontent = 'google-site-verification: google1111111111111.html'
68
+ @search_engine = new_search_engine(
69
+ :verification_file => @filename,
70
+ :verification_content => @filecontent)
71
+ SearchEngine.stubs(:signatory_folder).returns(TEST_FILES_FOLDER)
72
+ @search_engine.save
73
+ @expected_file = "#{TEST_FILES_FOLDER}/#{@filename}"
74
+ end
75
+ teardown do
76
+ teardown_test_folder
77
+ end
78
+ should 'know it it has a signatory file' do
79
+ assert @search_engine.has_signatory_file?
80
+ end
81
+ should 'create file and fill content' do
82
+ expected_file = "#{TEST_FILES_FOLDER}/#{@filename}"
83
+ assert File.exist?(expected_file), "File was not created upon creation"
84
+ file = File.new(expected_file)
85
+ assert_equal @filecontent, file.read
86
+ file.close
87
+ end
88
+ should 'remove file upon destruction' do
89
+ assert File.exist?(@expected_file)
90
+ @search_engine.destroy
91
+ assert !File.exist?(@expected_file)
92
+ end
93
+ context 'being modified' do
94
+ setup do
95
+ @new_filename = "google222222222222.html"
96
+ @new_content = 'google-site-verification: google222222222222.html'
97
+ end
98
+ should 'rename file if changed' do
99
+ @search_engine.verification_file = @new_filename
100
+ @search_engine.save
101
+ assert !File.exist?("#{TEST_FILES_FOLDER}/#{@filename}")
102
+ assert File.exist?("#{TEST_FILES_FOLDER}/#{@new_filename}")
103
+ end
104
+ should 'change content if changed' do
105
+ @search_engine.verification_content = @new_content
106
+ @search_engine.save
107
+ file = File.new(@expected_file)
108
+ assert_equal @new_content, file.read
109
+ file.close
110
+ end
111
+ end
112
+ context 'verification' do
113
+ setup do
114
+ flunk unless File.exist?(@expected_file)
115
+ File.delete(@expected_file)
116
+ flunk if File.exist?(@expected_file)
117
+ SearchEngine.verify_signatories!
118
+ end
119
+ should 'create signatory files' do
120
+ assert File.exist?(@expected_file)
121
+ end
122
+ end
123
+
124
+ end
125
+
126
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bcms_sitemap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Knut Stenmark
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-17 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: browsercms
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 3.0.6
24
+ version:
25
+ description: Warning. Not tested in production environment yet. Sitemap submitter module for BrowserCMS, which enables submission of sitemap to different search engines
26
+ email: knut.stenmark@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE.txt
33
+ - README.markdown
34
+ files:
35
+ - app/controllers/cms/search_engines_controller.rb
36
+ - app/controllers/sitemaps_controller.rb
37
+ - app/helpers/sitemaps_helper.rb
38
+ - app/models/search_engine.rb
39
+ - app/views/cms/search_engines/_form.html.erb
40
+ - app/views/cms/search_engines/edit.html.erb
41
+ - app/views/cms/search_engines/index.html.erb
42
+ - app/views/cms/search_engines/new.html.erb
43
+ - app/views/cms/shared/_admin_sidebar.html.erb
44
+ - app/views/sitemaps/index.builder
45
+ - app/views/sitemaps/model.builder
46
+ - app/views/sitemaps/news_articles.builder
47
+ - config/initializers/bcms_sitemap.rb
48
+ - config/initializers/init_module.rb
49
+ - db/migrate/20100212083005_create_search_engines.rb
50
+ - lib/bcms_sitemap.rb
51
+ - lib/bcms_sitemap/routes.rb
52
+ - lib/bcms_sitemap/sitemap_submitter.rb
53
+ - lib/tasks/bcms_sitemap.rake
54
+ - lib/tasks/sitemap.rake
55
+ - rails/init.rb
56
+ - LICENSE.txt
57
+ - README.markdown
58
+ has_rdoc: true
59
+ homepage: http://github.com/stonefield/bcms_sitemap
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.5
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Sitemap submitter module for BrowserCMS
86
+ test_files:
87
+ - test/functional/sitemaps_controller_test.rb
88
+ - test/integration/sitemap_submitter_test.rb
89
+ - test/performance/browsing_test.rb
90
+ - test/test_factory.rb
91
+ - test/test_helper.rb
92
+ - test/unit/helpers/sitemaps_helper_test.rb
93
+ - test/unit/search_engine_test.rb