Integration tests for forum validation, it works!
parent
35345f9cf4
commit
707592b25d
|
@ -22,7 +22,7 @@ class ForumValidation < ActiveRecord::Base
|
|||
if bot.authenticated? || authenticate_bot
|
||||
if user_forum_id = bot.get_user_id(author.forum_name)
|
||||
this_pm_sent = bot.send_pm(user_forum_id, I18n.t('forum_validations.pm.subject'), pm_message)
|
||||
self.pm_sent = pm_sent || this_pm_sent
|
||||
update_column(:pm_sent, true) if this_pm_sent
|
||||
this_pm_sent
|
||||
else
|
||||
# User that we're trying to send a PM to wasn't found. This shouldn't
|
||||
|
@ -46,16 +46,16 @@ class ForumValidation < ActiveRecord::Base
|
|||
part_1 = I18n.t 'forum_validations.pm.message',
|
||||
author_name: author.forum_name,
|
||||
email: user.email,
|
||||
url: Rails.application.routes.url_helpers.validate_forum_validation_url(self, vid: vid)
|
||||
url: Rails.application.routes.url_helpers.update_forum_validation_url(self, vid: vid)
|
||||
|
||||
mods_list = author.mods.where(owner: nil).map do |mod|
|
||||
url = Rails.application.routes.url_helpers.mod_url(mod)
|
||||
"- [url=#{url}]#{mod.name}[/url]"
|
||||
end.join('\n')
|
||||
end.join("\n")
|
||||
|
||||
part_2 = I18n.t 'forum_validations.pm.notice'
|
||||
|
||||
part_1 + "\n" + mods_list + "\n" + part_2
|
||||
part_1 + "\n\n" + mods_list + "\n\n" + part_2
|
||||
end
|
||||
|
||||
def self.bot
|
||||
|
|
|
@ -24,8 +24,8 @@ en:
|
|||
The mods currently associated with this account are:
|
||||
|
||||
notice: |
|
||||
If you didn't ask for this validation, please ignore
|
||||
this message, or reply to this PM indicating so, so Zequez can investigate the issue.
|
||||
If you didn't ask for this validation, please ignore this message,
|
||||
or reply to this PM indicating so, so Zequez can investigate the issue.
|
||||
|
||||
Thanks, the FactorioMods forum bot.
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ Rails.application.routes.draw do
|
|||
|
||||
resources :forum_validations, path: 'forum-validations', only: [:new, :show, :create] do
|
||||
member do
|
||||
get '/validate', to: 'forum_validations#update'
|
||||
get '/validate', to: 'forum_validations#update', as: :update
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
feature 'New user forum account validation' do
|
||||
scenario 'user registers, submits the validation form, then visits the link' do
|
||||
author = create :author, name: 'FactorioModsBot', forum_name: 'FactorioModsBot'
|
||||
another_dude = create :user
|
||||
m1 = create :mod, authors: [author], owner: nil
|
||||
m2 = create :mod, authors: [author], owner: nil
|
||||
create :mod, authors: [author], owner: another_dude
|
||||
create :mod, owner: nil
|
||||
|
||||
visit new_user_registration_path
|
||||
within '#new_registration' do
|
||||
fill_in 'user_email', with: 'potato@universe.com'
|
||||
fill_in 'user_forum_name', with: 'FactorioModsBot'
|
||||
fill_in 'user_password', with: '12345678'
|
||||
find('#user_submit_action input').click
|
||||
end
|
||||
|
||||
expect(current_path).to eq new_forum_validation_path
|
||||
|
||||
user = User.last
|
||||
expect(user.email).to eq 'potato@universe.com'
|
||||
expect(user.forum_name).to eq 'FactorioModsBot'
|
||||
|
||||
VCR.use_cassette("features/forum_validation", record: :new_episodes) do
|
||||
find('#forum_validation_submit_action input').click
|
||||
end
|
||||
|
||||
fv = ForumValidation.last
|
||||
|
||||
expect(current_path).to eq forum_validation_path fv
|
||||
|
||||
expect(fv.user).to eq user
|
||||
expect(fv.author).to eq author
|
||||
expect(fv.validated?).to eq false
|
||||
expect(fv.pm_sent?).to eq true
|
||||
|
||||
visit update_forum_validation_path(fv, vid: fv.vid)
|
||||
|
||||
expect(current_path).to eq forum_validation_path fv
|
||||
|
||||
fv.reload
|
||||
|
||||
expect(fv.validated?).to eq true
|
||||
expect(user.mods).to match_array [m1, m2]
|
||||
expect(user.author).to eq author
|
||||
end
|
||||
|
||||
scenario "user registers, but the forum_account given doesn't have any author" do
|
||||
visit new_user_registration_path
|
||||
within '#new_registration' do
|
||||
fill_in 'user_email', with: 'potato@universe.com'
|
||||
fill_in 'user_forum_name', with: 'FactorioModsBot'
|
||||
fill_in 'user_password', with: '12345678'
|
||||
find('#user_submit_action input').click
|
||||
end
|
||||
|
||||
expect(current_path).to eq root_path
|
||||
end
|
||||
end
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue