Skip to content

Commit

Permalink
Merge pull request #181 from tdiary/rdb-testing
Browse files Browse the repository at this point in the history
RDB の環境でもテスト可能にする対応
  • Loading branch information
hsbt committed Sep 25, 2012
2 parents 2391982 + 7b7eb0a commit 1588606
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 22 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ group :development do
gem 'rspec'
gem 'capybara', :require => 'capybara/rspec'
gem 'launchy'
gem 'sequel'
gem 'sqlite3'

gem 'rcov', :platforms => :mri_18
platforms :mri_19 do
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ GEM
libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
sequel (3.39.0)
simplecov (0.6.4)
multi_json (~> 1.0)
simplecov-html (~> 0.5.3)
Expand All @@ -124,6 +125,7 @@ GEM
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.6)
tapp (1.4.0)
thor
test-unit (2.5.2)
Expand Down Expand Up @@ -161,9 +163,11 @@ DEPENDENCIES
redcarpet
rspec
rubypython (= 0.5.1)
sequel
simplecov
simplecov-rcov
sprockets
sqlite3
tapp
test-unit
therubyracer
Expand Down
4 changes: 2 additions & 2 deletions misc/plugin/disp_referrer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def initialize( setup )
def cache( date )
return File.join( @setup['cache_dir'], 'volatile.tdr2.cache' ) unless date
begin
Dir.mkdir( @setup['cache_dir'] )
Dir.mkdir( @setup['cache_dir'].untaint )
rescue Errno::EEXIST
end
File.join( @setup['cache_dir'], date.strftime( '%Y%m.tdr2.cache' ) )
Expand Down Expand Up @@ -564,7 +564,7 @@ def update!
options_key = "disp_referrer2.#{key}"
self[key] = @options[options_key] if @options.has_key?( options_key )
end
self['no_cache'] = true if @conf.io_class == ::TDiary::DefaultIO
self['no_cache'] = true if defined?(::TDiary::DefaultIO) && @conf.io_class == ::TDiary::DefaultIO

# additions
self['labels'] = {
Expand Down
6 changes: 3 additions & 3 deletions spec/acceptance/save_conf_referer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'acceptance_helper'

feature 'リンク元設定の利用' do
scenario 'リンク元の非表示設定' do
scenario 'リンク元の非表示設定', :exclude_rdb do
append_default_diary
visit '/update.rb?conf=referer'
select('非表示', :from => 'show_referer')
Expand All @@ -15,7 +15,7 @@
within('div.day') { page.should have_no_css('div[class="refererlist"]') }
end

scenario 'リンク元記録の除外設定が動いている' do
scenario 'リンク元記録の除外設定が動いている', :exclude_rdb do
append_default_diary
visit '/update.rb?conf=referer'
fill_in 'no_referer', :with => '^http://www\.example\.com/.*'
Expand All @@ -28,7 +28,7 @@
within('div.day div.refererlist') { page.should have_no_link('http://www.example.com') }
end

scenario 'リンク元の置換が動いている', :exclude_selenium do
scenario 'リンク元の置換が動いている', :exclude_selenium, :exclude_rdb do
append_default_diary
visit '/update.rb?conf=referer'
fill_in 'referer_table', :with => <<-REFERER
Expand Down
65 changes: 49 additions & 16 deletions spec/acceptance_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,75 @@
Capybara.save_and_open_page_path = File.dirname(__FILE__) + '/../tmp/capybara'

RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true

fixture_conf = File.expand_path('../fixtures/just_installed.conf', __FILE__)
tdiary_conf = File.expand_path("../fixtures/tdiary.conf.#{ENV['TEST_MODE'] || 'rack'}", __FILE__)
work_data_dir = File.expand_path('../../tmp/data', __FILE__)
work_conf = File.expand_path('../../tdiary.conf', __FILE__)

config.treat_symbols_as_metadata_keys_with_true_values = true
tdiary_conf = File.expand_path("../fixtures/tdiary.conf.#{ENV['TEST_MODE'] || 'rack'}", __FILE__)
work_conf = File.expand_path('../../tdiary.conf', __FILE__)

config.before(:all) do
FileUtils.cp_r tdiary_conf, work_conf, :verbose => false
end

config.after(:all) do
FileUtils.rm_r work_conf
end

config.before(:each) do
FileUtils.mkdir_p work_data_dir
FileUtils.cp_r fixture_conf, File.join(work_data_dir, "tdiary.conf"), :verbose => false unless fixture_conf.empty?
end

config.after(:each) do
FileUtils.rm_r work_data_dir
end

config.after(:all) do
FileUtils.rm_r work_conf
if ENV['TEST_MODE'] == 'rdb'
work_db = 'sqlite://tmp/tdiary_test.db'
config.before(:each) do
Sequel.connect(work_db) do |db|
db.create_table :conf do
String :body, :text => true
end
db[:conf].insert(:body => File.read(fixture_conf))
end
end

config.after(:each) do
Sequel.connect(work_db) do |db|
[:diaries, :comments, :conf].each do |table|
db.drop_table(table) if db.table_exists? table
end
end
end
else
config.before(:each) do
FileUtils.cp_r(fixture_conf, File.join(work_data_dir, "tdiary.conf"), :verbose => false) unless fixture_conf.empty?
end

config.after(:each) do
FileUtils.rm_r File.join(work_data_dir, "tdiary.conf")
end
end

case ENV['TEST_MODE']
when 'webrick'
if ENV['TEST_MODE'] == 'webrick'
Capybara.default_driver = :selenium
Capybara.app_host = 'http://localhost:' + (ENV['PORT'] || '19292')
config.filter_run_excluding :exclude_selenium
config.filter_run_excluding :exclude_no_secure
when 'secure'
config.filter_run_excluding :exclude_rack
config.filter_run_excluding :exclude_secure
else
config.filter_run_excluding :exclude_rack
config.filter_run_excluding :exclude_no_secure
end

excludes = case ENV['TEST_MODE']
when 'webrick'
[:exclude_selenium, :exclude_no_secure]
when 'secure'
[:exclude_rack, :exclude_secure]
when 'rdb'
[:exclude_rdb, :exclude_rack, :exclude_no_secure]
else
[:exclude_rack, :exclude_no_secure]
end
excludes.each do |exclude|
config.filter_run_excluding exclude
end
end

Expand Down
Loading

0 comments on commit 1588606

Please sign in to comment.