Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Testing ruote-dm
- #
- # Sun Aug 9 19:39:16 JST 2009
- #
- require File.join(File.dirname(__FILE__), 'path_helper')
- require 'test/unit'
- require 'rubygems'
- require 'ruby-debug'
- Debugger.start
- require 'dm-core'
- DataMapper.setup(:default, {
- :adapter => 'postgres',
- :database => "alumni_development",
- :username => 'denis',
- :password => '',
- :host => 'localhost',
- :encoding => 'unicode',
- :pool => 1
- })
- DataMapper::Logger.new(STDOUT, 0)
- require 'ruote/dm/storage/dm_storage.rb'
- require 'ruote/dm/part/dm_participant.rb'
- DataMapper.repository(:default) do
- Ruote::Dm::DmExpression.auto_upgrade!
- Ruote::Dm::DmWorkitem.auto_upgrade!
- end
- require 'ruote/engine'
- require 'ruote/part/fs_participant'
- require 'ruote/dm/engine'
- require 'ruote/fei'
- require 'ruote/workitem'
- require 'ruote/dm/part/dm_participant'
- class ParticipantTest < Test::Unit::TestCase
- def setup
- setup_engine
- @launchitem = Ruote::Launchitem.new(define_webflow_processus,:association_id => 1,:registrar_id => 125,:locale => 'fr_BE')
- end
- def teardown
- DataMapper.repository(:default) do
- Ruote::Dm::DmWorkitem.all.destroy!
- end
- end
- def test_stop_at_first_user_as_dmparticipant
- register_user_as_dmparticipant_with_bloc
- @engine.launch(@launchitem)
- sleep 5
- #must stop at the first DMWorker the user one
- assert_equal 1, Ruote::Dm::DmWorkitem.all.size
- assert_not_nil Ruote::Dm::DmWorkitem.first.last_modified
- end
- def test_stop_at_first_user_as_dmparticipant
- register_user_as_dmparticipant_without_bloc
- @engine.launch(@launchitem)
- sleep 5
- #must stop at the first DMWorker the user one
- assert_equal 1, Ruote::Dm::DmWorkitem.all.size
- assert_not_nil Ruote::Dm::DmWorkitem.first.last_modified
- end
- protected
- def define_webflow_processus
- Ruote.process_definition :name => 'Registration process' do
- sequence do
- setup
- look_for_matching_profile
- _if :test => "${f:match_profile_status} == no" do
- sequence do
- # Two things, alert the admins and give them work
- alert :role => "superuser or admin_of_group :association", :message => "Could not match ${f:registrar_id} in association ${f:association_id}"
- guest_email :type => "profile_does_not_match"
- #need user interaction process must stop here
- user :role => "superuser or admin_of_group :association", :activity => "Registration matching failed"
- end
- end
- _if :test => "${f:match_profile_status} == active" do
- sequence do
- # Two things, alert the admins and give them work
- guest_email :type => "profile_already_activated" ,:redirect_url => 'lost_password'
- alert :role => "superuser or admin_of_group :association", :message => "Registrar ${f:registrar_id} in association ${f:association_id} try to register an active account ${f:match_profile_errors.join(', ')}"
- end
- end
- _if :test => "${f:match_profile_status} == yes" do
- sequence do
- # Two things, alert the admins and give them work
- #send an email for confirming the email et finish the comletion of the profile
- guest_email :type => "profile_already_activated",:redirect_url => 'double_optin'
- associate_registrar_with_his_matched_profile
- #wait for the registrar to complete his profile
- #need user interaction process must stop here
- user :user_id => "${f:user_id}", :activity => "double optin registration"
- #need user interaction process must stop here
- user :role => "superuser or admin_of_group :association", :activity => "validate matched profile"
- _if :test => "${f:matched_profile_activated} == true " do
- sequence do
- activated_matched_profile
- user_email :user_id => "${f:user_id}", :type => "account activated"
- end
- #_else
- sequence do
- #workitem contains subject and
- user_email :user_id => "${f:user_id}", :type => "account refused"
- end
- end
- end
- alert :message => "something wrong with match_profile_status :${f:match_profile_status}\n"
- end
- end
- process_definition "setup" do
- set :f => "match_profile_status", :val => "tobematched"
- set :f => "match_profile_errors", :val => []
- set :f => "matched_user_id", :val => ''
- set :f => "matched_profile_validated", :val => false
- end
- end
- end
- def setup_engine
- application_context = {}
- application_context[:engine_class] ||= Ruote::Dm::DmPersistedEngine #Ruote::Extras::ArPersistedEngine
- application_context[:work_directory] ||= "#{File.dirname(__FILE__)}/work"
- application_context[:ruby_eval_allowed] ||= true
- # the 'reval' expression and the ${r:some_ruby_code} notation are allowed
- application_context[:dynamic_eval_allowed] ||= true
- # the 'eval' expression is allowed
- application_context[:definition_in_launchitem_allowed] ||= true
- # launchitems (process_items) may contain process definitions
- engine_class = application_context.delete(:engine_class)
- @engine = engine_class.new(application_context)
- @engine.register_participant :alert do |workitem|
- puts "Alert : #{}"
- end
- @engine.register_participant :guest_email do |workitem|
- puts "guest_email : #{inspect_params(workitem)}\n"
- end
- @engine.register_participant :user_email do |workitem|
- puts "user_email : #{inspect_params(workitem)}\n"
- end
- @engine.register_participant :look_for_matching_profile do |workitem|
- puts "look_for_matching_profile : #{inspect_params(workitem)}\n"
- workitem.fields["match_profile_status"]= 'no' #'yes'
- workitem.fields["matched_user_id"] = nil # 123
- end
- @engine.register_participant :activated_matched_profile do |workitem|
- puts "activated_matched_profile : #{inspect_params(workitem)}\n"
- workitem.fields["matched_profile_validated"]= true
- end
- @engine.register_participant :associate_registrar_with_his_matched_profile do |workitem|
- #flag registrar
- puts "activated_matched_profile : #{inspect_params(workitem)}\n"
- workitem.fields["matched_profile_activated"]= true
- end
- end
- def register_user_as_dmparticipant_with_bloc
- #::Ruote::Dm::DmParticipant
- @engine.register_participant :user, ::Ruote::Dm::DmParticipant do |workitem|
- puts "user : #{inspect_params(workitem)}\n"
- end
- end
- def register_user_as_dmparticipant_without_bloc
- #::Ruote::Dm::DmParticipant
- @engine.register_participant :user, ::Ruote::Dm::DmParticipant
- end
- def register_user_as_fsparticipant
- #::Ruote::Dm::DmParticipant
- @engine.register_participant :user, ::Ruote::FsParticipant
- end
- end
Add Comment
Please, Sign In to add comment