Commit 46ea17994199c92e236ff02338846e02db50c21d
Exists in
master
and in
29 other branches
Merge remote-tracking branch 'larissa/stoa-plugin-rails3' into larissa-stoa-plugin-rails3
Showing
11 changed files
with
54 additions
and
58 deletions
Show diff stats
app/models/image.rb
lib/noosfero/plugin.rb
... | ... | @@ -395,7 +395,7 @@ class Noosfero::Plugin |
395 | 395 | end |
396 | 396 | |
397 | 397 | # -> Adds fields to the signup form |
398 | - # returns = lambda block that creates html code | |
398 | + # returns = proc that creates html code | |
399 | 399 | def signup_extra_contents |
400 | 400 | nil |
401 | 401 | end |
... | ... | @@ -470,7 +470,7 @@ class Noosfero::Plugin |
470 | 470 | end |
471 | 471 | |
472 | 472 | # -> Adds fields to the login form |
473 | - # returns = lambda block that creates html code | |
473 | + # returns = proc that creates html code | |
474 | 474 | def login_extra_contents |
475 | 475 | nil |
476 | 476 | end | ... | ... |
plugins/stoa/lib/ext/person.rb
1 | 1 | require_dependency 'person' |
2 | 2 | |
3 | 3 | class Person |
4 | + attr_accessible :usp_id, :invitation_code | |
5 | + | |
4 | 6 | validates_uniqueness_of :usp_id, :allow_nil => true |
5 | 7 | settings_items :invitation_code |
6 | 8 | validate :usp_id_or_invitation, :if => lambda { |person| person.environment && person.environment.plugin_enabled?(StoaPlugin)} | ... | ... |
plugins/stoa/lib/stoa_plugin.rb
... | ... | @@ -2,8 +2,6 @@ require_dependency 'person' |
2 | 2 | |
3 | 3 | class StoaPlugin < Noosfero::Plugin |
4 | 4 | |
5 | - Person.human_names[:usp_id] = _('USP number') | |
6 | - | |
7 | 5 | def self.plugin_name |
8 | 6 | "Stoa" |
9 | 7 | end |
... | ... | @@ -17,7 +15,7 @@ class StoaPlugin < Noosfero::Plugin |
17 | 15 | end |
18 | 16 | |
19 | 17 | def signup_extra_contents |
20 | - lambda { | |
18 | + proc { | |
21 | 19 | content_tag(:div, labelled_form_field(_('USP number'), text_field(:profile_data, :usp_id, :id => 'usp_id_field')) + |
22 | 20 | content_tag(:small, _('The usp id grants you special powers in the network. Don\'t forget to fill it with a valid number if you have one.'), :id => 'usp-id-balloon') + |
23 | 21 | content_tag('p', _("Either this usp number is being used by another user or is not valid"), :id => 'usp-id-invalid') + |
... | ... | @@ -45,7 +43,7 @@ class StoaPlugin < Noosfero::Plugin |
45 | 43 | end |
46 | 44 | |
47 | 45 | def login_extra_contents |
48 | - lambda { | |
46 | + proc { | |
49 | 47 | content_tag('div', labelled_form_field(_('USP number / Username'), text_field_tag('usp_id_login', '', :id => 'stoa_field_login')) + |
50 | 48 | labelled_form_field(_('Password'), password_field_tag('password', '', :id => 'stoa_field_password')), :id => 'stoa-login-fields') |
51 | 49 | } |
... | ... | @@ -62,14 +60,13 @@ class StoaPlugin < Noosfero::Plugin |
62 | 60 | end |
63 | 61 | |
64 | 62 | def account_controller_filters |
65 | - environment = context.environment | |
66 | - block = lambda do | |
63 | + block = lambda do |context| | |
67 | 64 | params[:profile_data] ||= {} |
68 | 65 | params[:profile_data][:invitation_code] = params[:invitation_code] |
69 | 66 | invitation = Task.pending.find(:first, :conditions => {:code => params[:invitation_code]}) |
70 | 67 | if request.post? |
71 | 68 | if !invitation && !StoaPlugin::UspUser.matches?(params[:profile_data][:usp_id], params[:confirmation_field], params[params[:confirmation_field]]) |
72 | - @person = Person.new(:environment => environment) | |
69 | + @person = Person.new(:environment => context.environment) | |
73 | 70 | @person.errors.add(:usp_id, _(' validation failed')) |
74 | 71 | render :action => :signup |
75 | 72 | end |
... | ... | @@ -83,7 +80,7 @@ class StoaPlugin < Noosfero::Plugin |
83 | 80 | end |
84 | 81 | |
85 | 82 | def profile_editor_controller_filters |
86 | - block = lambda do | |
83 | + block = proc do | |
87 | 84 | if request.post? |
88 | 85 | if !params[:profile_data][:usp_id].blank? && !StoaPlugin::UspUser.matches?(params[:profile_data][:usp_id], params[:confirmation_field], params[params[:confirmation_field]]) |
89 | 86 | @profile_data = profile |
... | ... | @@ -106,7 +103,7 @@ class StoaPlugin < Noosfero::Plugin |
106 | 103 | def invite_controller_filters |
107 | 104 | [{ :type => 'before_filter', |
108 | 105 | :method_name => 'check_usp_id_existence', |
109 | - :block => lambda {render_access_denied if !user || user.usp_id.blank?} }] | |
106 | + :block => proc {render_access_denied if !user || user.usp_id.blank?} }] | |
110 | 107 | end |
111 | 108 | |
112 | 109 | def control_panel_buttons | ... | ... |
plugins/stoa/lib/stoa_plugin/person_api.rb
... | ... | @@ -28,7 +28,7 @@ class StoaPlugin::PersonApi < Noosfero::FieldsDecorator |
28 | 28 | end |
29 | 29 | |
30 | 30 | def tags |
31 | - articles.published.tag_counts({:order => 'tags.count desc', :limit => 10}).inject({}) do |memo,tag| | |
31 | + articles.published.tag_counts({:order => 'count desc', :limit => 10}).inject({}) do |memo,tag| | |
32 | 32 | memo[tag.name] = tag.count |
33 | 33 | memo |
34 | 34 | end | ... | ... |
plugins/stoa/lib/stoa_plugin/usp_user.rb
... | ... | @@ -3,7 +3,7 @@ class StoaPlugin::UspUser < ActiveRecord::Base |
3 | 3 | establish_connection(:stoa) |
4 | 4 | set_table_name('pessoa') |
5 | 5 | |
6 | - SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt'] | |
6 | + SALT=YAML::load(File.open(StoaPlugin.root_path + 'config.yml'))['salt'] | |
7 | 7 | |
8 | 8 | alias_attribute :cpf, :numcpf |
9 | 9 | alias_attribute :birth_date, :dtanas | ... | ... |
plugins/stoa/test/functional/account_controller_test.rb
... | ... | @@ -6,32 +6,29 @@ class AccountController; def rescue_action(e) raise e end; end |
6 | 6 | |
7 | 7 | class AccountControllerTest < ActionController::TestCase |
8 | 8 | |
9 | - SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt'] | |
9 | + SALT=YAML::load(File.open(StoaPlugin.root_path + 'config.yml'))['salt'] | |
10 | + | |
11 | + @db = Tempfile.new('stoa-test') | |
12 | + configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path} | |
13 | + ActiveRecord::Base.establish_connection(:stoa) | |
14 | + ActiveRecord::Schema.verbose = false | |
15 | + ActiveRecord::Schema.create_table "pessoa" do |t| | |
16 | + t.integer "codpes" | |
17 | + t.text "numcpf" | |
18 | + t.date "dtanas" | |
19 | + end | |
20 | + ActiveRecord::Base.establish_connection(:test) | |
10 | 21 | |
11 | 22 | def setup |
12 | 23 | @controller = AccountController.new |
13 | 24 | @request = ActionController::TestRequest.new |
14 | 25 | @response = ActionController::TestResponse.new |
15 | - @db = Tempfile.new('stoa-test') | |
16 | - configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path} | |
17 | - ActiveRecord::Base.establish_connection(:stoa) | |
18 | - ActiveRecord::Schema.verbose = false | |
19 | - ActiveRecord::Schema.create_table "pessoa" do |t| | |
20 | - t.integer "codpes" | |
21 | - t.text "numcpf" | |
22 | - t.date "dtanas" | |
23 | - end | |
24 | - ActiveRecord::Base.establish_connection(:test) | |
25 | - StoaPlugin::UspUser.create!(:codpes => 12345678, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30') | |
26 | + StoaPlugin::UspUser.create!({:codpes => 12345678, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30'}, :without_protection => true) | |
26 | 27 | Environment.default.enable_plugin(StoaPlugin.name) |
27 | 28 | @user = create_user('joao-stoa', {:password => 'pass', :password_confirmation => 'pass'},:usp_id=>'87654321') |
28 | 29 | @user.activate |
29 | 30 | end |
30 | 31 | |
31 | - def teardown | |
32 | - @db.unlink | |
33 | - end | |
34 | - | |
35 | 32 | should 'fail if confirmation value doesn\'t match' do |
36 | 33 | #StoaPlugin::UspUser.stubs(:matches?).returns(false) |
37 | 34 | post :signup, :profile_data => {:usp_id => '12345678'}, :confirmation_field => 'cpf', :cpf => '00000000' |
... | ... | @@ -41,10 +38,10 @@ class AccountControllerTest < ActionController::TestCase |
41 | 38 | should 'pass if confirmation value matches' do |
42 | 39 | #StoaPlugin::UspUser.stubs(:matches?).returns(true) |
43 | 40 | post :signup, :profile_data => {:usp_id => '12345678'}, :confirmation_field => 'cpf', :cpf => '12345678' |
44 | - assert_nil assigns(:person).errors[:usp_id] | |
41 | + assert !assigns(:person).errors.include?(:usp_id) | |
45 | 42 | end |
46 | 43 | |
47 | - should 'inlude invitation_code param in the persons attributes' do | |
44 | + should 'include invitation_code param in the persons attributes' do | |
48 | 45 | get :signup, :invitation_code => 12345678 |
49 | 46 | assert assigns(:person).invitation_code == '12345678' |
50 | 47 | end | ... | ... |
plugins/stoa/test/functional/profile_editor_controller_test.rb
... | ... | @@ -6,7 +6,7 @@ class ProfileEditorController; def rescue_action(e) raise e end; end |
6 | 6 | |
7 | 7 | class StoaPluginProfileEditorControllerTest < ActionController::TestCase |
8 | 8 | |
9 | - SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt'] | |
9 | + SALT=YAML::load(File.open(StoaPlugin.root_path + 'config.yml'))['salt'] | |
10 | 10 | |
11 | 11 | def setup |
12 | 12 | @controller = ProfileEditorController.new |
... | ... | @@ -45,7 +45,7 @@ class StoaPluginProfileEditorControllerTest < ActionController::TestCase |
45 | 45 | should 'display error if usp_id does not match with supplied confirmation' do |
46 | 46 | StoaPlugin::UspUser.stubs(:matches?).returns(false) |
47 | 47 | post :edit, :profile => person.identifier, :profile_data => {:usp_id => 12345678}, :confirmation_field => 'cpf', :cpf => 99999999 |
48 | - assert assigns(:profile_data).errors.invalid?(:usp_id) | |
48 | + assert assigns(:profile_data).errors.include?(:usp_id) | |
49 | 49 | end |
50 | 50 | |
51 | 51 | should 'save usp_id if everyhtings is ok' do | ... | ... |
plugins/stoa/test/functional/stoa_plugin_controller_test.rb
... | ... | @@ -6,7 +6,7 @@ class StoaPluginController; def rescue_action(e) raise e end; end |
6 | 6 | |
7 | 7 | class StoaPluginControllerTest < ActionController::TestCase |
8 | 8 | |
9 | - SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt'] | |
9 | + SALT=YAML::load(File.open(StoaPlugin.root_path + 'config.yml'))['salt'] | |
10 | 10 | |
11 | 11 | def setup |
12 | 12 | @controller = StoaPluginController.new |
... | ... | @@ -18,6 +18,7 @@ class StoaPluginControllerTest < ActionController::TestCase |
18 | 18 | env.enable('skip_new_user_email_confirmation') |
19 | 19 | env.save! |
20 | 20 | @user = create_user_full('real_user', {:password => '123456', :password_confirmation => '123456'}, {:usp_id => 9999999}) |
21 | + @user.activate | |
21 | 22 | end |
22 | 23 | |
23 | 24 | attr_accessor :user | ... | ... |
plugins/stoa/test/unit/person_test.rb
... | ... | @@ -15,7 +15,7 @@ class StoaPlugin::Person < ActiveSupport::TestCase |
15 | 15 | another_person = Person.new(:usp_id => usp_id) |
16 | 16 | another_person.valid? |
17 | 17 | |
18 | - assert another_person.errors.invalid?(:usp_id) | |
18 | + assert another_person.errors.include?(:usp_id) | |
19 | 19 | end |
20 | 20 | |
21 | 21 | should 'not allow usp_id as an empty string' do |
... | ... | @@ -28,17 +28,17 @@ class StoaPlugin::Person < ActiveSupport::TestCase |
28 | 28 | should 'allow nil usp_id only if person has an invitation_code or is a template' do |
29 | 29 | person = Person.new(:environment => environment) |
30 | 30 | person.valid? |
31 | - assert person.errors.invalid?(:usp_id) | |
31 | + assert person.errors.include?(:usp_id) | |
32 | 32 | |
33 | 33 | Task.create!(:code => 12345678) |
34 | 34 | person.invitation_code = 12345678 |
35 | 35 | person.valid? |
36 | - assert !person.errors.invalid?(:usp_id) | |
36 | + assert !person.errors.include?(:usp_id) | |
37 | 37 | |
38 | 38 | person.invitation_code = nil |
39 | 39 | person.is_template = true |
40 | 40 | person.valid? |
41 | - assert !person.errors.invalid?(:usp_id) | |
41 | + assert !person.errors.include?(:usp_id) | |
42 | 42 | end |
43 | 43 | |
44 | 44 | should 'allow multiple nil usp_id' do |
... | ... | @@ -47,7 +47,7 @@ class StoaPlugin::Person < ActiveSupport::TestCase |
47 | 47 | person = Person.new(:invitation_code => 87654321) |
48 | 48 | person.valid? |
49 | 49 | |
50 | - assert !person.errors.invalid?(:usp_id) | |
50 | + assert !person.errors.include?(:usp_id) | |
51 | 51 | end |
52 | 52 | |
53 | 53 | should 'not allow person to be saved with a finished invitation that is not his own' do |
... | ... | @@ -56,7 +56,7 @@ class StoaPlugin::Person < ActiveSupport::TestCase |
56 | 56 | person = Person.new(:environment => environment, :invitation_code => 87654321) |
57 | 57 | person.valid? |
58 | 58 | |
59 | - assert person.errors.invalid?(:usp_id) | |
59 | + assert person.errors.include?(:usp_id) | |
60 | 60 | end |
61 | 61 | |
62 | 62 | should 'allow person to be saved with a finished invitation if it is his own' do |
... | ... | @@ -68,7 +68,7 @@ class StoaPlugin::Person < ActiveSupport::TestCase |
68 | 68 | t.finish |
69 | 69 | |
70 | 70 | person.valid? |
71 | - assert !person.errors.invalid?(:usp_id) | |
71 | + assert !person.errors.include?(:usp_id) | |
72 | 72 | end |
73 | 73 | |
74 | 74 | ... | ... |
plugins/stoa/test/unit/usp_user_test.rb
... | ... | @@ -2,24 +2,21 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | 2 | |
3 | 3 | class StoaPlugin::UspUserTest < ActiveSupport::TestCase |
4 | 4 | |
5 | - SALT=YAML::load(File.open(StoaPlugin.root_path + '/config.yml'))['salt'] | |
6 | - | |
7 | - def setup | |
8 | - @db = Tempfile.new('stoa-test') | |
9 | - configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path} | |
10 | - ActiveRecord::Base.establish_connection(:stoa) | |
11 | - ActiveRecord::Schema.verbose = false | |
12 | - ActiveRecord::Schema.create_table "pessoa" do |t| | |
13 | - t.integer "codpes" | |
14 | - t.text "numcpf" | |
15 | - t.date "dtanas" | |
16 | - end | |
17 | - ActiveRecord::Base.establish_connection(:test) | |
18 | - StoaPlugin::UspUser.create!(:codpes => 123456, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30') | |
5 | + SALT=YAML::load(File.open(StoaPlugin.root_path + 'config.yml'))['salt'] | |
6 | + | |
7 | + @db = Tempfile.new('stoa-test') | |
8 | + configs = ActiveRecord::Base.configurations['stoa'] = {:adapter => 'sqlite3', :database => @db.path} | |
9 | + ActiveRecord::Base.establish_connection(:stoa) | |
10 | + ActiveRecord::Schema.verbose = false | |
11 | + ActiveRecord::Schema.create_table "pessoa" do |t| | |
12 | + t.integer "codpes" | |
13 | + t.text "numcpf" | |
14 | + t.date "dtanas" | |
19 | 15 | end |
16 | + ActiveRecord::Base.establish_connection(:test) | |
20 | 17 | |
21 | - def teardown | |
22 | - @db.unlink | |
18 | + def setup | |
19 | + StoaPlugin::UspUser.create({:codpes => 123456, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30'}, :without_protection => true) | |
23 | 20 | end |
24 | 21 | |
25 | 22 | should 'check existence of usp_id' do |
... | ... | @@ -48,4 +45,3 @@ class StoaPlugin::UspUserTest < ActiveSupport::TestCase |
48 | 45 | assert !StoaPlugin::UspUser.matches?(123456, nil, '00012345678') |
49 | 46 | end |
50 | 47 | end |
51 | - | ... | ... |