impostor 0.2.1 → 1.0.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.
- data/.gemtest +0 -0
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +47 -0
- data/History.txt +8 -0
- data/Manifest.txt +87 -55
- data/README.txt +11 -11
- data/Rakefile +16 -20
- data/lib/impostor/auth.rb +103 -0
- data/lib/impostor/config.rb +171 -0
- data/lib/impostor/errors.rb +67 -0
- data/lib/impostor/phpbb2.rb +202 -0
- data/lib/impostor/phpbb3.rb +199 -0
- data/lib/impostor/post.rb +111 -0
- data/lib/impostor/topic.rb +115 -0
- data/lib/impostor/wwf79.rb +186 -0
- data/lib/impostor/wwf80.rb +190 -0
- data/lib/impostor.rb +108 -5
- data/spec/auth_spec.rb +148 -0
- data/spec/base_spec_helper.rb +12 -0
- data/{test/test_helper.rb → spec/caged_net_http.rb} +8 -17
- data/spec/config_spec.rb +136 -0
- data/spec/fixtures/junk.html +1 -0
- data/{test → spec}/fixtures/phpbb2-get-new_topic-form-good-response.html +0 -0
- data/{test → spec}/fixtures/phpbb2-get-viewtopic-for-new-topic-good-response.html +11 -11
- data/{test → spec}/fixtures/phpbb2-get-viewtopic-for-new-topic-malformed-response.html +0 -0
- data/{test → spec}/fixtures/phpbb2-index.html +0 -0
- data/{test → spec}/fixtures/phpbb2-logged-in.html +0 -0
- data/{test → spec}/fixtures/phpbb2-login.html +0 -0
- data/{test → spec}/fixtures/phpbb2-not-logged-in.html +0 -0
- data/{test → spec}/fixtures/phpbb2-post-new_topic-good-response.html +0 -0
- data/{test → spec}/fixtures/phpbb2-post-reply-good-response.html +0 -0
- data/{test → spec}/fixtures/phpbb2-post-reply-throttled-response.html +0 -0
- data/{test → spec}/fixtures/phpbb2-too-many-posts.html +0 -0
- data/{test → spec}/fixtures/phpbb3-get-new-topic-form-good-response.html +0 -0
- data/{test → spec}/fixtures/phpbb3-get-reply-form-good-response.html +0 -0
- data/{test → spec}/fixtures/phpbb3-logged-in.html +0 -0
- data/{test → spec}/fixtures/phpbb3-login.html +0 -0
- data/{test → spec}/fixtures/phpbb3-not-logged-in.html +0 -0
- data/{test → spec}/fixtures/phpbb3-post-new_topic-good-response.html +0 -0
- data/{test → spec}/fixtures/phpbb3-post-reply-good-response.html +0 -0
- data/spec/fixtures/vcr_cassettes/phpbb2-should-be-overlimit-creating-topic.yml +1308 -0
- data/spec/fixtures/vcr_cassettes/phpbb2-should-create-topic.yml +923 -0
- data/spec/fixtures/vcr_cassettes/phpbb2-should-login.yml +360 -0
- data/spec/fixtures/vcr_cassettes/phpbb2-should-not-create-new-topic.yml +497 -0
- data/spec/fixtures/vcr_cassettes/phpbb2-should-not-login.yml +287 -0
- data/spec/fixtures/vcr_cassettes/phpbb2-should-not-post.yml +497 -0
- data/spec/fixtures/vcr_cassettes/phpbb2-should-overlimit-error-post.yml +1140 -0
- data/spec/fixtures/vcr_cassettes/phpbb2-should-post.yml +751 -0
- data/spec/fixtures/vcr_cassettes/phpbb3-should-be-overlimit-creating-topic.yml +995 -0
- data/spec/fixtures/vcr_cassettes/phpbb3-should-create-topic.yml +675 -0
- data/spec/fixtures/vcr_cassettes/phpbb3-should-login.yml +245 -0
- data/spec/fixtures/vcr_cassettes/phpbb3-should-not-create-new-topic.yml +350 -0
- data/spec/fixtures/vcr_cassettes/phpbb3-should-not-login.yml +253 -0
- data/spec/fixtures/vcr_cassettes/phpbb3-should-not-post.yml +350 -0
- data/spec/fixtures/vcr_cassettes/phpbb3-should-overlimit-error-post.yml +1046 -0
- data/spec/fixtures/vcr_cassettes/phpbb3-should-post.yml +605 -0
- data/{test → spec}/fixtures/wwf79-forum_posts.html +0 -0
- data/{test → spec}/fixtures/wwf79-general-new-topic-error.html +0 -0
- data/{test → spec}/fixtures/wwf79-general-posting-error.html +0 -0
- data/{test → spec}/fixtures/wwf79-good-post-forum_posts.html +1 -1
- data/{test → spec}/fixtures/wwf79-index.html +0 -0
- data/{test → spec}/fixtures/wwf79-logged-in.html +0 -0
- data/{test → spec}/fixtures/wwf79-login.html +0 -0
- data/{test → spec}/fixtures/wwf79-new-topic-forum_posts-response.html +0 -0
- data/{test → spec}/fixtures/wwf79-new-topic-post_message_form.html +0 -0
- data/{test → spec}/fixtures/wwf79-not-logged-in.html +0 -0
- data/{test → spec}/fixtures/wwf79-too-many-posts.html +0 -0
- data/{test → spec}/fixtures/wwf79-too-many-topics.html +0 -0
- data/{test → spec}/fixtures/wwf80-general-posting-error.html +0 -0
- data/{test → spec}/fixtures/wwf80-get-new_topic-form-good-response.html +0 -0
- data/{test → spec}/fixtures/wwf80-get-viewtopic-for-new-topic-good-response.html +0 -0
- data/{test → spec}/fixtures/wwf80-index.html +0 -0
- data/{test → spec}/fixtures/wwf80-logged-in.html +0 -0
- data/{test → spec}/fixtures/wwf80-login.html +0 -0
- data/{test → spec}/fixtures/wwf80-new_reply_form.html +0 -0
- data/{test → spec}/fixtures/wwf80-not-logged-in.html +0 -0
- data/{test → spec}/fixtures/wwf80-post-new_topic-good-response.html +1 -1
- data/{test → spec}/fixtures/wwf80-post-reply-good-response.html +0 -0
- data/{test → spec}/fixtures/wwf80-too-many-posts.html +0 -0
- data/spec/impostor_spec_helper.rb +162 -0
- data/spec/integration/phpbb2_spec.rb +111 -0
- data/spec/integration/phpbb3_spec.rb +109 -0
- data/spec/integration_spec_helper.rb +7 -0
- data/spec/phpbb2_spec.rb +346 -0
- data/spec/phpbb3_spec.rb +332 -0
- data/spec/post_spec.rb +134 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/test_impostor.rb +12 -0
- data/spec/topic_spec.rb +143 -0
- data/spec/wwf79_spec.rb +342 -0
- data/spec/wwf80_spec.rb +339 -0
- metadata +156 -87
- data/lib/www/impostor/phpbb2.rb +0 -258
- data/lib/www/impostor/phpbb3.rb +0 -236
- data/lib/www/impostor/wwf79.rb +0 -254
- data/lib/www/impostor/wwf80.rb +0 -264
- data/lib/www/impostor.rb +0 -269
- data/test/test_github.rb +0 -12
- data/test/test_www_impostor.rb +0 -165
- data/test/test_www_impostor_phpbb2.rb +0 -536
- data/test/test_www_impostor_phpbb3.rb +0 -483
- data/test/test_www_impostor_wwf79.rb +0 -535
- data/test/test_www_impostor_wwf80.rb +0 -535
- data/vendor/plugins/impostor/lib/autotest/discover.rb +0 -3
- data/vendor/plugins/impostor/lib/autotest/impostor.rb +0 -49
data/lib/www/impostor.rb
DELETED
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
|
-
Dir.glob(File.join(File.dirname(__FILE__), 'impostor/*.rb')).each {|f| require f }
|
|
3
|
-
|
|
4
|
-
module WWW
|
|
5
|
-
|
|
6
|
-
##
|
|
7
|
-
# imPOSTor posts messages to non-RESTful forums and blogs
|
|
8
|
-
#
|
|
9
|
-
# == Example
|
|
10
|
-
# require 'rubygems'
|
|
11
|
-
# require 'impostor'
|
|
12
|
-
#
|
|
13
|
-
# # config yaml has options specefic to wwf79, wwf80, phpbb2, etc.
|
|
14
|
-
# # read the impostor docs for options to the kind of forum in use
|
|
15
|
-
# # config can be keyed by symbols or strings
|
|
16
|
-
# post = WWW::Impostor.new(YAML.load_file('config.yml'))
|
|
17
|
-
# message = %q!hello world is to application
|
|
18
|
-
# programmers as tea pots are to graphics programmers!
|
|
19
|
-
# # your application store forum and topic ids
|
|
20
|
-
# post.post(forum=5,topic=10,message)
|
|
21
|
-
# # make a new topic
|
|
22
|
-
# subject = "about programmers..."
|
|
23
|
-
# post.new_topic(forum=7,subject,message)
|
|
24
|
-
# post.logout
|
|
25
|
-
#
|
|
26
|
-
# keys and values that can be set in the impostor configuration
|
|
27
|
-
#
|
|
28
|
-
# :type - kind of imPOSTor, :phpbb2, :wwf79, :wwf80, etc.
|
|
29
|
-
# :username - forum username
|
|
30
|
-
# :password - forum password
|
|
31
|
-
# :topics_cache - cache of forum topics
|
|
32
|
-
# :user_agent - Mechanize browser user-agent
|
|
33
|
-
# :cookie_jar - saved cookies from Mechanize browser
|
|
34
|
-
# :app_root - url to forum
|
|
35
|
-
# :login_page - forum login page
|
|
36
|
-
#
|
|
37
|
-
# See documentation for each type of imPOSTor for additional configuration
|
|
38
|
-
# parameters that are needed for the specific kind of imPOSTor. A sample
|
|
39
|
-
# configuration is provided in the documentation for each.
|
|
40
|
-
|
|
41
|
-
class Impostor
|
|
42
|
-
|
|
43
|
-
class << self #:nodoc:
|
|
44
|
-
alias orig_new new
|
|
45
|
-
def new(conf)
|
|
46
|
-
klass = WWW::Impostor.create(conf)
|
|
47
|
-
klass.orig_new(conf)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
##
|
|
52
|
-
# Gem version of Impostor
|
|
53
|
-
|
|
54
|
-
VERSION = '0.2.1'
|
|
55
|
-
|
|
56
|
-
##
|
|
57
|
-
# An application error
|
|
58
|
-
|
|
59
|
-
class ImpostorError < RuntimeError
|
|
60
|
-
|
|
61
|
-
##
|
|
62
|
-
# The original exception
|
|
63
|
-
|
|
64
|
-
attr_accessor :original_exception
|
|
65
|
-
|
|
66
|
-
##
|
|
67
|
-
# Creates a new ImpostorError with +message+ and +original_exception+
|
|
68
|
-
|
|
69
|
-
def initialize(e)
|
|
70
|
-
exception = e.class == String ? StandardError.new(e) : e
|
|
71
|
-
@original_exception = exception
|
|
72
|
-
message = "Impostor error: #{exception.message} (#{exception.class})"
|
|
73
|
-
super message
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
##
|
|
79
|
-
# An error for impostor login failure
|
|
80
|
-
|
|
81
|
-
class LoginError < ImpostorError; end
|
|
82
|
-
|
|
83
|
-
##
|
|
84
|
-
# An error for impostor post failure
|
|
85
|
-
|
|
86
|
-
class PostError < ImpostorError; end
|
|
87
|
-
|
|
88
|
-
##
|
|
89
|
-
# An error for impostor when a topic id can't be found based on a
|
|
90
|
-
# name/title.
|
|
91
|
-
|
|
92
|
-
class TopicError < ImpostorError; end
|
|
93
|
-
|
|
94
|
-
##
|
|
95
|
-
# An error for impostor when the receiving forum rejects the post due to
|
|
96
|
-
# a throttling or spam error but which the user can re-attempt at a later
|
|
97
|
-
# time.
|
|
98
|
-
|
|
99
|
-
class ThrottledError < ImpostorError; end
|
|
100
|
-
|
|
101
|
-
##
|
|
102
|
-
# Pass in a config hash to initialize
|
|
103
|
-
|
|
104
|
-
def initialize(conf={})
|
|
105
|
-
@config = conf
|
|
106
|
-
load_topics
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
##
|
|
110
|
-
# Instantiate a specific impostor based on its symbol name
|
|
111
|
-
|
|
112
|
-
def self.create(conf={})
|
|
113
|
-
type = conf[:type] || conf[:type.to_s]
|
|
114
|
-
clz = type.is_a?(Class) ? type : eval("WWW::Impostor::#{type.to_s.capitalize}")
|
|
115
|
-
clz
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
##
|
|
119
|
-
# Access the current config and key it without regard for symbols or strings
|
|
120
|
-
|
|
121
|
-
def config(*key)
|
|
122
|
-
return @config if key.empty?
|
|
123
|
-
@config[key.first.to_sym] || @config[key.first.to_s]
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
##
|
|
127
|
-
# Get/set the application version that impostor is interfacing with
|
|
128
|
-
|
|
129
|
-
attr_accessor :version
|
|
130
|
-
|
|
131
|
-
##
|
|
132
|
-
# Login to the forum, returns true if logged in, false otherwise
|
|
133
|
-
|
|
134
|
-
def login; end
|
|
135
|
-
|
|
136
|
-
##
|
|
137
|
-
# Log out of the forum, true if logged in, false otherwise
|
|
138
|
-
|
|
139
|
-
def logout; end
|
|
140
|
-
|
|
141
|
-
##
|
|
142
|
-
# Load the topics that the impostor already knows about
|
|
143
|
-
|
|
144
|
-
def load_topics
|
|
145
|
-
cache = config[:topics_cache] ||= ""
|
|
146
|
-
if File::exist?(cache)
|
|
147
|
-
@topics = YAML::load_file(cache)
|
|
148
|
-
else
|
|
149
|
-
@topics = Hash.new
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
##
|
|
154
|
-
# Add subject to topics hash
|
|
155
|
-
|
|
156
|
-
def add_subject(forum,topic,name)
|
|
157
|
-
if @topics[forum].nil?
|
|
158
|
-
@topics[forum] = {topic, name}
|
|
159
|
-
else
|
|
160
|
-
@topics[forum][topic] = name
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
##
|
|
165
|
-
# Save the topics
|
|
166
|
-
|
|
167
|
-
def save_topics
|
|
168
|
-
cache = config[:topics_cache] ||= ""
|
|
169
|
-
if File::exist?(cache)
|
|
170
|
-
File.open(cache, 'w') do |out|
|
|
171
|
-
YAML.dump(@topics, out)
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
##
|
|
177
|
-
# Post the message
|
|
178
|
-
|
|
179
|
-
def post(forum = @forum, topic = @topic, message = @message); end
|
|
180
|
-
|
|
181
|
-
##
|
|
182
|
-
# get/set the current message
|
|
183
|
-
|
|
184
|
-
attr_accessor :message
|
|
185
|
-
|
|
186
|
-
##
|
|
187
|
-
# get/set the current subject
|
|
188
|
-
|
|
189
|
-
attr_accessor :subject
|
|
190
|
-
|
|
191
|
-
##
|
|
192
|
-
# Get/set the form id
|
|
193
|
-
|
|
194
|
-
attr_accessor :forum
|
|
195
|
-
|
|
196
|
-
##
|
|
197
|
-
# Get/set the topic id
|
|
198
|
-
|
|
199
|
-
attr_accessor :topic
|
|
200
|
-
|
|
201
|
-
##
|
|
202
|
-
# Get the topic name (subject) based on forum and topic ids
|
|
203
|
-
|
|
204
|
-
def get_subject(forum = @forum, topic = @topic)
|
|
205
|
-
if @topics && @topics[forum]
|
|
206
|
-
return @topics[forum][topic]
|
|
207
|
-
end
|
|
208
|
-
nil
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
##
|
|
212
|
-
# Make a new topic
|
|
213
|
-
|
|
214
|
-
def new_topic(forum=@forum, subject=@subject, message=@message); end
|
|
215
|
-
|
|
216
|
-
##
|
|
217
|
-
# Gets the application root of the application such as
|
|
218
|
-
# http://example.com/phpbb or http://example.com/forums
|
|
219
|
-
|
|
220
|
-
def app_root
|
|
221
|
-
config[:app_root]
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
protected
|
|
225
|
-
|
|
226
|
-
##
|
|
227
|
-
# Get the topics cache
|
|
228
|
-
|
|
229
|
-
def topics_cache
|
|
230
|
-
config[:topics_cache]
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
##
|
|
234
|
-
# Get the login page for the application
|
|
235
|
-
|
|
236
|
-
def login_page
|
|
237
|
-
URI.join(app_root, config[:login_page])
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
##
|
|
241
|
-
# Get the username for the application
|
|
242
|
-
|
|
243
|
-
def username
|
|
244
|
-
config[:username]
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
##
|
|
248
|
-
# Get the password for the application
|
|
249
|
-
|
|
250
|
-
def password
|
|
251
|
-
config[:password]
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
##
|
|
255
|
-
# A Mechanize user agent name, see the mechanize documentation
|
|
256
|
-
# 'Linux Mozilla', 'Mac Safari', 'Windows IE 7', etc.
|
|
257
|
-
|
|
258
|
-
def user_agent
|
|
259
|
-
config[:user_agent]
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
##
|
|
263
|
-
# is a yaml file for WWW::Mechanize::CookieJar
|
|
264
|
-
|
|
265
|
-
def cookie_jar
|
|
266
|
-
config[:cookie_jar]
|
|
267
|
-
end
|
|
268
|
-
end
|
|
269
|
-
end
|
data/test/test_github.rb
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
require 'test/unit'
|
|
2
|
-
require 'rubygems'
|
|
3
|
-
|
|
4
|
-
class TestGithub < Test::Unit::TestCase
|
|
5
|
-
|
|
6
|
-
def test_build_github_gem
|
|
7
|
-
result = `ruby #{File.join(File.dirname(__FILE__), "..", "dev_tools", "github.rb")}`
|
|
8
|
-
puts result
|
|
9
|
-
assert_equal 0, $?.exitstatus
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
end
|
data/test/test_www_impostor.rb
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "lib", "www", "impostor")
|
|
2
|
-
require File.join(File.dirname(__FILE__), "test_helper")
|
|
3
|
-
|
|
4
|
-
require 'tempfile'
|
|
5
|
-
require 'test/unit'
|
|
6
|
-
|
|
7
|
-
class TestWwwImpostor < Test::Unit::TestCase
|
|
8
|
-
|
|
9
|
-
def test_impostor_error
|
|
10
|
-
message = 'test message'
|
|
11
|
-
error = WWW::Impostor::ImpostorError.new(StandardError.new(message))
|
|
12
|
-
assert error
|
|
13
|
-
assert_equal message, error.original_exception.message
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def test_create_should_return_an_instance
|
|
17
|
-
im = WWW::Impostor.create({:type => :fake})
|
|
18
|
-
assert_equal WWW::Impostor::Fake, im
|
|
19
|
-
im = WWW::Impostor.create({:type => WWW::Impostor::Fake})
|
|
20
|
-
assert_equal WWW::Impostor::Fake, im
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def test_aliased_new_returns_custom_impostor_instance
|
|
24
|
-
im = WWW::Impostor.new({:type => :fake})
|
|
25
|
-
assert_equal WWW::Impostor::Fake, im.class
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def test_add_subject_should_work
|
|
29
|
-
im = fake
|
|
30
|
-
im.add_subject(f=10,t=10,s="hello world")
|
|
31
|
-
assert_equal s, im.get_subject(f,t)
|
|
32
|
-
im.add_subject(f=10,t=11,s="hello world2")
|
|
33
|
-
assert_equal s, im.get_subject(f,t)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def test_config_should_not_be_nil
|
|
37
|
-
assert_nothing_raised(StandardError) do
|
|
38
|
-
impostor = fake({:key => 'val'})
|
|
39
|
-
assert impostor.config
|
|
40
|
-
assert_equal 'val', impostor.config('key')
|
|
41
|
-
assert_equal 'val', impostor.config(:key)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def test_login_page_should_be_clean
|
|
46
|
-
impostor = fake({:app_root => 'http://localhost/', :login_page => '/foo/bar'})
|
|
47
|
-
assert_equal 'http://localhost/foo/bar', impostor.test_helper_login_page.to_s
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def test_load_topics_should_do_so
|
|
51
|
-
# setup a temp file
|
|
52
|
-
topics_file = Tempfile.new('test_load_topics')
|
|
53
|
-
|
|
54
|
-
# make some topics
|
|
55
|
-
topics_path = topics_file.path
|
|
56
|
-
topics_file.close
|
|
57
|
-
forum = 7
|
|
58
|
-
topic = 5
|
|
59
|
-
topics = {forum => { topic => 'my topic title'}}
|
|
60
|
-
#
|
|
61
|
-
# dump the topics out
|
|
62
|
-
File.open(topics_path, 'w') do |out|
|
|
63
|
-
YAML.dump(topics, out)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# make an impostor and ensure the topics are correct
|
|
67
|
-
impostor = fake({:topics_cache => topics_file.path})
|
|
68
|
-
assert_equal 'my topic title', impostor.get_subject(forum, topic)
|
|
69
|
-
assert_equal nil, impostor.get_subject(82, 101)
|
|
70
|
-
|
|
71
|
-
#dump the test file
|
|
72
|
-
topics_file.unlink
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def test_topics_should_save_and_load
|
|
76
|
-
# setup a temp file
|
|
77
|
-
topics_file = Tempfile.new('test_load_topics')
|
|
78
|
-
|
|
79
|
-
# make some topics
|
|
80
|
-
topics_path = topics_file.path
|
|
81
|
-
topics_file.close
|
|
82
|
-
forum_one = 7
|
|
83
|
-
topic_one = 5
|
|
84
|
-
topics = {forum_one => { topic_one => 'my topic title'}}
|
|
85
|
-
|
|
86
|
-
# dump the topics out
|
|
87
|
-
File.open(topics_path, 'w') do |out|
|
|
88
|
-
YAML.dump(topics, out)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
# make an impostor, add a topic, save
|
|
92
|
-
forum_two = 8
|
|
93
|
-
topic_two = 22
|
|
94
|
-
impostor = fake({:topics_cache => topics_file.path})
|
|
95
|
-
impostor.test_helper_add_topic(forum_one, topic_two, 'hello world')
|
|
96
|
-
impostor.test_helper_add_topic(forum_two, topic_two, 'foo bar')
|
|
97
|
-
|
|
98
|
-
impostor.save_topics
|
|
99
|
-
|
|
100
|
-
# get a new impostor and make sure the topics were saved
|
|
101
|
-
impostor = fake({:topics_cache => topics_file.path})
|
|
102
|
-
assert_equal 'my topic title', impostor.get_subject(forum_one, topic_one)
|
|
103
|
-
assert_equal 'hello world', impostor.get_subject(forum_one, topic_two)
|
|
104
|
-
assert_equal 'foo bar', impostor.get_subject(forum_two, topic_two)
|
|
105
|
-
assert_equal nil, impostor.get_subject(82, 101)
|
|
106
|
-
|
|
107
|
-
# test topics_cache
|
|
108
|
-
assert_equal topics_file.path, impostor.test_helper_topics_cache
|
|
109
|
-
|
|
110
|
-
#dump the test file
|
|
111
|
-
topics_file.unlink
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
def test_get_subject_should_return_something_when_forum_and_topic_are_set
|
|
115
|
-
|
|
116
|
-
# setup a temp file
|
|
117
|
-
topics_file = Tempfile.new('test_load_topics')
|
|
118
|
-
|
|
119
|
-
# make some topics
|
|
120
|
-
topics_path = topics_file.path
|
|
121
|
-
topics_file.close
|
|
122
|
-
forum = 7
|
|
123
|
-
topic = 5
|
|
124
|
-
topics = {forum => { topic => 'my topic title'}}
|
|
125
|
-
#
|
|
126
|
-
# dump the topics out
|
|
127
|
-
File.open(topics_path, 'w') do |out|
|
|
128
|
-
YAML.dump(topics, out)
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
# make an impostor and ensure the topic name is correct
|
|
132
|
-
impostor = fake({:topics_cache => topics_file.path})
|
|
133
|
-
impostor.forum = forum
|
|
134
|
-
impostor.topic = topic
|
|
135
|
-
assert_equal 'my topic title', impostor.get_subject
|
|
136
|
-
|
|
137
|
-
#clean up
|
|
138
|
-
topics_file.unlink
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
private
|
|
142
|
-
|
|
143
|
-
class WWW::Impostor::Fake < WWW::Impostor
|
|
144
|
-
def test_helper_login_page
|
|
145
|
-
login_page
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
def test_helper_posting_page
|
|
149
|
-
posting_page
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def test_helper_topics_cache
|
|
153
|
-
topics_cache
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
def test_helper_add_topic(f,t,n)
|
|
157
|
-
@topics[f].nil? ? @topics[f] = {t => n} : @topics[f][t] = n
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def fake(config = {})
|
|
162
|
-
config[:type] = :fake
|
|
163
|
-
WWW::Impostor.new(config)
|
|
164
|
-
end
|
|
165
|
-
end
|