ixtlan 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +49 -0
- data/MIT-LICENSE +20 -0
- data/Manifest.txt +73 -48
- data/Rakefile +1 -1
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/gwt_ixtlan_datamapper_rspec_scaffold_generator.rb +3 -3
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/AbstractApplicationResourceTestGwt.java +1 -1
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Fields.java +1 -1
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Model.java +2 -2
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/ModelFactory.java +2 -2
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Screen.java +2 -2
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/TestGwt.java +2 -2
- data/generators/ixtlan_datamapper_rspec_model/ixtlan_datamapper_rspec_model_generator.rb +1 -1
- data/generators/ixtlan_datamapper_rspec_scaffold/ixtlan_datamapper_rspec_scaffold_generator.rb +4 -4
- data/generators/ixtlan_datamapper_rspec_scaffold/templates/guard.rb +7 -7
- data/generators/ixtlan_datamapper_rspec_scaffold/templates/i18n.rb +1 -1
- data/generators/ixtlan_datamapper_rspec_scaffold/templates/layout.html.erb +20 -0
- data/ixtlan_rails_templates.rb +537 -0
- data/lib/ixtlan/audit_config.rb +5 -5
- data/lib/ixtlan/child_path.rb +2 -2
- data/lib/ixtlan/cms_script.rb +4 -4
- data/lib/ixtlan/controllers/authentications_controller.rb +7 -2
- data/lib/ixtlan/controllers/configurations_controller.rb +15 -6
- data/lib/ixtlan/controllers/domains_controller.rb +99 -0
- data/lib/ixtlan/controllers/groups_controller.rb +105 -0
- data/lib/ixtlan/controllers/locales_controller.rb +99 -0
- data/lib/ixtlan/controllers/permissions_controller.rb +5 -0
- data/lib/ixtlan/controllers/phrases_controller.rb +26 -22
- data/lib/ixtlan/controllers/search_query.rb +24 -0
- data/lib/ixtlan/controllers/texts_controller.rb +5 -5
- data/lib/ixtlan/controllers/users_controller.rb +117 -0
- data/lib/ixtlan/controllers/word_bundles_controller.rb +13 -8
- data/lib/ixtlan/digest.rb +3 -3
- data/lib/ixtlan/guard.rb +11 -12
- data/lib/ixtlan/logger_config.rb +11 -11
- data/lib/ixtlan/mailer/error_notification.erb +1 -0
- data/lib/ixtlan/mailer/password.erb +1 -0
- data/lib/ixtlan/mailer.rb +27 -0
- data/lib/ixtlan/models/authentication.rb +9 -6
- data/lib/ixtlan/models/configuration.rb +21 -37
- data/lib/ixtlan/models/configuration_locale.rb +3 -3
- data/lib/ixtlan/models/domain.rb +44 -0
- data/lib/ixtlan/models/domain_group_user.rb +22 -0
- data/lib/ixtlan/models/group.rb +82 -16
- data/lib/ixtlan/models/group_locale_user.rb +4 -4
- data/lib/ixtlan/models/group_user.rb +7 -7
- data/lib/ixtlan/models/i18n_text.rb +26 -26
- data/lib/ixtlan/models/locale.rb +17 -5
- data/lib/ixtlan/models/permission.rb +3 -2
- data/lib/ixtlan/models/phrase.rb +15 -15
- data/lib/ixtlan/models/role.rb +5 -5
- data/lib/ixtlan/models/translation.rb +9 -9
- data/lib/ixtlan/models/update_children.rb +74 -0
- data/lib/ixtlan/models/user.rb +108 -16
- data/lib/ixtlan/models/word.rb +2 -1
- data/lib/ixtlan/models.rb +1 -0
- data/lib/ixtlan/modified_by.rb +9 -7
- data/lib/ixtlan/monkey_patches.rb +5 -5
- data/lib/ixtlan/optimistic_persistence.rb +2 -2
- data/lib/ixtlan/optimistic_persistence_module.rb +3 -3
- data/lib/ixtlan/optimistic_persistence_validation.rb +2 -2
- data/lib/ixtlan/passwords.rb +15 -13
- data/lib/ixtlan/rails/error_handling.rb +41 -40
- data/lib/ixtlan/rails/guard.rb +0 -1
- data/lib/ixtlan/rails/migrations.rb +75 -0
- data/lib/ixtlan/rails/session_timeout.rb +16 -14
- data/lib/ixtlan/rails/timestamps_modified_by_filter.rb +1 -1
- data/lib/ixtlan/rails/unrestful_authentication.rb +4 -4
- data/lib/ixtlan/rolling_file.rb +3 -3
- data/lib/ixtlan/session.rb +4 -3
- data/lib/ixtlan/user_logger.rb +13 -9
- data/lib/ixtlan/version.rb +1 -1
- data/spec/authentication_spec.rb +1 -1
- data/spec/guard_spec.rb +4 -4
- data/spec/guards/samples.rb +7 -7
- data/spec/modified_by_spec.rb +82 -0
- data/spec/optimistic_persistence_spec.rb +58 -0
- data/spec/phrase_spec.rb +119 -0
- data/spec/session_timeout_spec.rb +59 -0
- data/spec/spec_helper.rb +6 -5
- data/spec/text_collection_spec.rb +88 -0
- data/spec/text_spec.rb +105 -0
- data/spec/unrestful_authentication_spec.rb +142 -0
- data/spec/user_logger_spec.rb +105 -0
- data/spec/user_spec.rb +249 -0
- data/whitespace.rb +31 -0
- metadata +76 -50
- data/lib/ixtlan/error_notifier/error_notification.rhtml +0 -1
data/spec/phrase_spec.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require Pathname(__FILE__).dirname + 'spec_helper.rb'
|
3
|
+
|
4
|
+
require Pathname(__FILE__).dirname + '../lib/dm-serializer/to_xml'
|
5
|
+
|
6
|
+
|
7
|
+
require 'ixtlan/controllers/texts_controller'
|
8
|
+
|
9
|
+
require 'ixtlan/models/i18n_text'
|
10
|
+
require 'ixtlan/models/word'
|
11
|
+
require 'ixtlan/models/translation'
|
12
|
+
require 'ixtlan/models/phrase'
|
13
|
+
|
14
|
+
def setup(code)
|
15
|
+
len = 6
|
16
|
+
Controller.send(:include, Ixtlan::Controllers::TextsController)
|
17
|
+
Ixtlan::Models::I18nText.all.destroy!
|
18
|
+
Ixtlan::Models::Locale.all.destroy!
|
19
|
+
Ixtlan::Models::Locale.first_or_create(:id => 1, :code => "DEFAULT")
|
20
|
+
@controller2 = Controller.new
|
21
|
+
@en = Ixtlan::Models::Locale.first_or_create(:id => 1000, :code => "en")
|
22
|
+
@en_in = Ixtlan::Models::Locale.first_or_create(:id => 2000, :code => "en_IN")
|
23
|
+
(1..len).each do |j|
|
24
|
+
text = Ixtlan::Models::I18nText.create(:id => j,
|
25
|
+
:code => code,
|
26
|
+
:text => "text_#{j}",
|
27
|
+
:current_user => @controller2.current_user,
|
28
|
+
:locale => Ixtlan::Models::Locale.default,
|
29
|
+
:updated_at => DateTime.now,
|
30
|
+
:updated_by => @controller2.current_user)
|
31
|
+
|
32
|
+
text.approve(:current_user => @controller2.current_user)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
#describe Ixtlan::Models::Phrase do
|
37
|
+
|
38
|
+
|
39
|
+
describe "with default locale" do
|
40
|
+
before(:each) do
|
41
|
+
setup("cccc_1")
|
42
|
+
end
|
43
|
+
it "should xml-serialize" do
|
44
|
+
#Ixtlan::Models::I18nText.all.each {|t| p t}
|
45
|
+
Ixtlan::Models::Phrase.all(:code => "cccc_1").to_xml.cleanup.should == "<phrases><phrase><code>cccc_1</code><text>text_6</text><current_text>text_6</current_text><updated_at>date</updated_at><updated_by_id>1</updated_by_id><locale><id>1</id><code>DEFAULT</code><created_at>date</created_at></locale></phrase></phrases>"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "with default locale" do
|
50
|
+
before(:each) do
|
51
|
+
setup("cccc_2")
|
52
|
+
end
|
53
|
+
it "should xml-serialize with edited text" do
|
54
|
+
Ixtlan::Models::I18nText.create(:code => "cccc_2",
|
55
|
+
:text => "text_edited",
|
56
|
+
:current_user => @controller2.current_user,
|
57
|
+
:locale => Ixtlan::Models::Locale.default,
|
58
|
+
:updated_at => DateTime.now,
|
59
|
+
:updated_by => @controller2.current_user)
|
60
|
+
# Ixtlan::Models::I18nText.all.each {|t| p t}
|
61
|
+
Ixtlan::Models::Phrase.all(:code => "cccc_2").to_xml.cleanup.should == "<phrases><phrase><code>cccc_2</code><text>text_edited</text><current_text>text_6</current_text><updated_at>date</updated_at><updated_by_id>1</updated_by_id><locale><id>1</id><code>DEFAULT</code><created_at>date</created_at></locale></phrase></phrases>"
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
describe "with default locale" do
|
66
|
+
before(:each) do
|
67
|
+
setup("cccc_3")
|
68
|
+
Ixtlan::Models::I18nText.all.destroy!
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should xml-serialize with edited text and not approved" do
|
72
|
+
Ixtlan::Models::I18nText.create(:code => "cccc_3",
|
73
|
+
:text => "text_edited",
|
74
|
+
:current_user => @controller2.current_user,
|
75
|
+
:locale => Ixtlan::Models::Locale.default,
|
76
|
+
:updated_at => DateTime.now,
|
77
|
+
:updated_by => @controller2.current_user)
|
78
|
+
#Ixtlan::Models::I18nText.all.each {|t| p t}
|
79
|
+
Ixtlan::Models::Phrase.all(:code => "cccc_3").to_xml.cleanup.should == "<phrases><phrase><code>cccc_3</code><text>text_edited</text><current_text>text_edited</current_text><updated_at>date</updated_at><updated_by_id>1</updated_by_id><locale><id>1</id><code>DEFAULT</code><created_at>date</created_at></locale></phrase></phrases>"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "with 'de' locale" do
|
84
|
+
before(:each) do
|
85
|
+
setup("de_code")
|
86
|
+
end
|
87
|
+
it "should xml-serialize" do
|
88
|
+
#Ixtlan::Models::I18nText.all.each {|t| p t}
|
89
|
+
Ixtlan::Models::Phrase.all(:code => "de_code", :locale => Ixtlan::Models::Locale.first_or_create(:id => 3000, :code => 'de')).to_xml.cleanup.should == "<phrases><phrase><code>de_code</code><text>text_6</text><current_text>text_6</current_text><updated_at>date</updated_at><updated_by_id>1</updated_by_id><default_translation><text>text_6</text><previous_text>text_5</previous_text><approved_at>date</approved_at><approved_by_id>1</approved_by_id></default_translation><locale><id>3000</id><code>de</code><created_at>date</created_at></locale></phrase></phrases>"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "with 'en' locale" do
|
94
|
+
before(:each) do
|
95
|
+
setup("en_code")
|
96
|
+
|
97
|
+
Ixtlan::Models::I18nText.create(:code => "en_code",
|
98
|
+
:text => "en_text_edited",
|
99
|
+
:current_user => @controller2.current_user,
|
100
|
+
:locale => @en,
|
101
|
+
:updated_at => DateTime.now,
|
102
|
+
:updated_by => @controller2.current_user)
|
103
|
+
Ixtlan::Models::I18nText.create(:code => "en_code",
|
104
|
+
:text => "en_in_text_edited",
|
105
|
+
:current_user => @controller2.current_user,
|
106
|
+
:locale => @en_in,
|
107
|
+
:updated_at => DateTime.now,
|
108
|
+
:updated_by => @controller2.current_user)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should xml-serialize with edited text" do
|
112
|
+
#Ixtlan::Models::I18nText.all(:code => "en_code").each {|t| puts "code=#{t.code} locale=#{t.locale.code} version=#{t.version} current=#{t.current} previous=#{t.previous}"}
|
113
|
+
Ixtlan::Models::Phrase.all(:code => "en_code", :locale => @en).to_xml.cleanup.should == "<phrases><phrase><code>en_code</code><text>en_text_edited</text><current_text>en_text_edited</current_text><updated_at>date</updated_at><updated_by_id>1</updated_by_id><default_translation><text>text_6</text><previous_text>text_5</previous_text><approved_at>date</approved_at><approved_by_id>1</approved_by_id></default_translation><locale><id>1000</id><code>en</code><created_at>date</created_at></locale></phrase></phrases>"
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
#end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require Pathname(__FILE__).dirname + 'spec_helper.rb'
|
3
|
+
|
4
|
+
require 'ixtlan/rails/session_timeout'
|
5
|
+
|
6
|
+
class Controller
|
7
|
+
include Ixtlan::Rails::SessionTimeout
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Ixtlan::Rails::SessionTimeout do
|
11
|
+
|
12
|
+
before :each do
|
13
|
+
Ixtlan::Models::User.all.destroy!
|
14
|
+
@controller = Controller.new
|
15
|
+
@log = StringIO.new
|
16
|
+
Slf4r::LoggerFacade4RubyLogger.file = @log
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should expire due to idle timeout' do
|
20
|
+
@controller.send(:check_session_expiry).should be_true
|
21
|
+
@controller.session.empty?.should be_false
|
22
|
+
@controller.rendered.should be_nil
|
23
|
+
@log.string.size.should == 0
|
24
|
+
sleep 1
|
25
|
+
@controller.send(:check_session_expiry).should be_false
|
26
|
+
@controller.session.empty?.should be_true
|
27
|
+
@controller.rendered.should be_true
|
28
|
+
@log.string.size.should_not == 0
|
29
|
+
@log.string.should =~ /session timeout/
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should expire due to IP change' do
|
33
|
+
@controller.request.headers['REMOTE_ADDR'] = "first.ip"
|
34
|
+
@controller.send(:check_session_ip_binding).should be_true
|
35
|
+
@controller.session.empty?.should be_false
|
36
|
+
@controller.rendered.should be_nil
|
37
|
+
@log.string.size.should == 0
|
38
|
+
@controller.request.headers['REMOTE_ADDR'] = "second.ip"
|
39
|
+
@controller.send(:check_session_ip_binding).should be_false
|
40
|
+
@controller.session.empty?.should be_true
|
41
|
+
@controller.rendered.should be_true
|
42
|
+
@log.string.size.should_not == 0
|
43
|
+
@log.string.should =~ /IP changed/
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should expire due to IP change' do
|
47
|
+
@controller.request.headers['HTTP_USER_AGENT'] = "mozilla"
|
48
|
+
@controller.send(:check_session_browser_signature).should be_true
|
49
|
+
@controller.session.empty?.should be_false
|
50
|
+
@controller.rendered.should be_nil
|
51
|
+
@log.string.size.should == 0
|
52
|
+
@controller.request.headers['HTTP_USER_AGENT'] = "iron"
|
53
|
+
@controller.send(:check_session_browser_signature).should be_false
|
54
|
+
@controller.session.empty?.should be_true
|
55
|
+
@controller.rendered.should be_true
|
56
|
+
@log.string.size.should_not == 0
|
57
|
+
@log.string.should =~ /browser signature changed/
|
58
|
+
end
|
59
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -12,9 +12,10 @@ require 'slf4r'
|
|
12
12
|
require 'ixtlan' / 'models'
|
13
13
|
require 'ixtlan' / 'user_logger'
|
14
14
|
require 'ixtlan' / 'modified_by'
|
15
|
-
require 'ixtlan' / 'models' / '
|
15
|
+
require 'ixtlan' / 'models' / 'domain'
|
16
16
|
require 'ixtlan' / 'models' / 'locale'
|
17
17
|
require 'ixtlan' / 'models' / 'group'
|
18
|
+
require 'ixtlan' / 'models' / 'user'
|
18
19
|
require 'ixtlan' / 'models' / 'configuration'
|
19
20
|
require 'ixtlan' / 'models' / 'group_user'
|
20
21
|
require 'ixtlan' / 'models' / 'group_locale_user'
|
@@ -64,7 +65,7 @@ class Controller
|
|
64
65
|
def initialize
|
65
66
|
@params = {}
|
66
67
|
u = Ixtlan::Models::User.first(:login => :marvin)
|
67
|
-
if u.nil?
|
68
|
+
if u.nil?
|
68
69
|
u = Ixtlan::Models::User.new(:login => :marvin, :name => 'marvin the robot', :email=> "marvin@universe.example.com", :language => "xx", :id => 1, :created_at => DateTime.now, :updated_at => DateTime.now)
|
69
70
|
if(u.respond_to? :created_by_id)
|
70
71
|
u.created_by_id = 1
|
@@ -132,15 +133,15 @@ if RUBY_PLATFORM =~ /java/
|
|
132
133
|
module DataMapper
|
133
134
|
module Validate
|
134
135
|
class NumericValidator
|
135
|
-
|
136
|
+
|
136
137
|
def validate_with_comparison(value, cmp, expected, error_message_name, errors, negated = false)
|
137
138
|
return if expected.nil?
|
138
|
-
if cmp == :=~
|
139
|
+
if cmp == :=~
|
139
140
|
return value =~ expected
|
140
141
|
end
|
141
142
|
comparison = value.send(cmp, expected)
|
142
143
|
return if negated ? !comparison : comparison
|
143
|
-
|
144
|
+
|
144
145
|
errors << ValidationErrors.default_error_message(error_message_name, field_name, expected)
|
145
146
|
end
|
146
147
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
|
2
|
+
require 'pathname'
|
3
|
+
require Pathname(__FILE__).dirname + 'spec_helper.rb'
|
4
|
+
|
5
|
+
require 'ixtlan/controllers/texts_controller'
|
6
|
+
|
7
|
+
require 'ixtlan/models/i18n_text'
|
8
|
+
require 'ixtlan/models/word'
|
9
|
+
require 'ixtlan/models/translation'
|
10
|
+
|
11
|
+
describe "Ixtlan::Models::TextCollection" do
|
12
|
+
|
13
|
+
len = 6
|
14
|
+
|
15
|
+
before(:all) do
|
16
|
+
Controller.send(:include, Ixtlan::Controllers::TextsController)
|
17
|
+
@controller = Controller.new
|
18
|
+
Ixtlan::Models::Locale.all.destroy!
|
19
|
+
Ixtlan::Models::I18nText.all.destroy!
|
20
|
+
(1..len).each do |i|
|
21
|
+
locale = Ixtlan::Models::Locale.first_or_create(:id => 10 + len + i, :code => "c#{(96 +i).chr}")
|
22
|
+
text = Ixtlan::Models::I18nText.create(:code => "code_#{i}",
|
23
|
+
:text => "text_#{i}",
|
24
|
+
:current_user => @controller.current_user,
|
25
|
+
:locale => Ixtlan::Models::Locale.default,
|
26
|
+
:updated_at => DateTime.now,
|
27
|
+
:updated_by => @controller.current_user)
|
28
|
+
text.approve(:current_user => @controller.current_user)
|
29
|
+
(1..len).each do |j|
|
30
|
+
text = Ixtlan::Models::I18nText.create(:code => "code_#{i}", :text => "text_#{i}_#{j}",
|
31
|
+
:current_user => @controller.current_user, :locale => locale, :updated_at => DateTime.now, :updated_by => @controller.current_user)
|
32
|
+
text.approve(:current_user => @controller.current_user) unless j == len
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have #{len} second latest approved" do
|
38
|
+
set = Ixtlan::Models::I18nText.second_latest_approved
|
39
|
+
set.size.should == len
|
40
|
+
set.each do |t|
|
41
|
+
t.version.should_not be_nil
|
42
|
+
t.current.should be_false
|
43
|
+
t.previous.should be_true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should have #{len * 2} latest approved" do
|
48
|
+
set = Ixtlan::Models::I18nText.latest_approved
|
49
|
+
set.size.should == len * 2
|
50
|
+
set.each do |t|
|
51
|
+
t.version.should_not be_nil
|
52
|
+
t.current.should be_true
|
53
|
+
t.previous.should be_false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should have #{len} not approved" do
|
58
|
+
set = Ixtlan::Models::I18nText.not_approved
|
59
|
+
set.size.should == len
|
60
|
+
set.each do |t|
|
61
|
+
t.version.should be_nil
|
62
|
+
t.current.should be_false
|
63
|
+
t.previous.should be_false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should have #{len * len} approved" do
|
68
|
+
Ixtlan::Models::I18nText.approved.size.should == len * len
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should have #{len * (len - 3)} old approved" do
|
72
|
+
Ixtlan::Models::I18nText.all(:current => false, :previous => false, :version.not => nil).size.should == len * (len - 3)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should have right number of approved when filterd by locale " do
|
76
|
+
locale = Ixtlan::Models::Locale.first_or_create(:code => "cb")
|
77
|
+
Ixtlan::Models::I18nText.approved(:locale => locale).size.should == len - 1
|
78
|
+
Ixtlan::Models::I18nText.latest_approved(:locale => locale).size.should == 1
|
79
|
+
Ixtlan::Models::I18nText.not_approved(:locale => locale).size.should == 1
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should setup the translation map' do
|
83
|
+
locale = Ixtlan::Models::Locale.first_or_create(:code => "cb")
|
84
|
+
map = Ixtlan::Models::Translation.map_for(:locale => locale)
|
85
|
+
map.size.should == 1
|
86
|
+
map.values[0].to_xml.gsub(/ type='[a-z:]*'/, '').gsub(/[0-9-]+T[0-9:]+\+[0-9:]+/, 'date').should == "<translation><text>text_2_5</text><previous_text>text_2_4</previous_text><approved_at>date</approved_at><approved_by_id>1</approved_by_id></translation>"
|
87
|
+
end
|
88
|
+
end
|
data/spec/text_spec.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
|
2
|
+
require 'pathname'
|
3
|
+
require Pathname(__FILE__).dirname + 'spec_helper.rb'
|
4
|
+
|
5
|
+
require 'ixtlan/controllers/texts_controller'
|
6
|
+
|
7
|
+
require 'ixtlan/models/i18n_text'
|
8
|
+
require 'ixtlan/models/word'
|
9
|
+
require 'ixtlan/models/translation'
|
10
|
+
|
11
|
+
describe Ixtlan::Models::I18nText do
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
@controller = Controller.new
|
15
|
+
Ixtlan::Models::I18nText.all.destroy!
|
16
|
+
@approved = Ixtlan::Models::I18nText.create(:code => "code", :text => "other text", :current_user => @controller.current_user, :locale => Ixtlan::Models::Locale.default)
|
17
|
+
@approved.approve(:current_user => @controller.current_user)
|
18
|
+
@text = Ixtlan::Models::I18nText.create(:code => "code", :text => "text", :current_user => @controller.current_user, :locale => Ixtlan::Models::Locale.default)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should create default" do
|
22
|
+
@text.new?.should_not be_nil
|
23
|
+
@text.id.should_not be_nil
|
24
|
+
@text.updated_at.should_not be_nil
|
25
|
+
@text.updated_by.should == @controller.current_user
|
26
|
+
@text.version.should be_nil
|
27
|
+
@text.current.should be_false
|
28
|
+
@text.approved_at.should be_nil
|
29
|
+
@text.approved_by.should be_nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should create translation' do
|
33
|
+
Ixtlan::Models::I18nText.create(:code => "code", :text => "text_en", :current_user => @controller.current_user, :locale => Ixtlan::Models::Locale.first_or_create(:code => 'en')).new?.should be_false
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should not create' do
|
37
|
+
Ixtlan::Models::I18nText.create(:code => "code2", :text => "text", :current_user => @controller.current_user, :locale => Ixtlan::Models::Locale.first_or_create(:code => 'en')).new?.should be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should update' do
|
41
|
+
text = Ixtlan::Models::I18nText.create(:code => "update_code", :text => "text", :current_user => @controller.current_user, :locale => Ixtlan::Models::Locale.default)
|
42
|
+
text.update(:text => 'new text', :current_user => @controller.current_user)
|
43
|
+
text.should be_true
|
44
|
+
text.version.should be_nil
|
45
|
+
text.current.should be_false
|
46
|
+
text.approved_at.should be_nil
|
47
|
+
text.approved_by.should be_nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should approve' do
|
51
|
+
text = Ixtlan::Models::I18nText.create(:code => "apporved_code", :text => "text", :current_user => @controller.current_user, :locale => Ixtlan::Models::Locale.default)
|
52
|
+
text.approved?.should be_false
|
53
|
+
text.approve(:current_user => @controller.current_user).should be_true
|
54
|
+
text.version.should_not be_nil
|
55
|
+
text.approved?.should be_true
|
56
|
+
text.current.should be_true
|
57
|
+
text.approved_at.should_not be_nil
|
58
|
+
text.approved_by.should_not be_nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should not update unapproved when changing text and version' do
|
62
|
+
@text.attributes = {:text => 'new text', :version => 1, :current_user => @controller.current_user}
|
63
|
+
@text.save.should be_false
|
64
|
+
@text.errors[:invariant].first.should == 'can not approve and change text at the same time'
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should not update approved on text change' do
|
68
|
+
|
69
|
+
@approved.version.should_not be_nil
|
70
|
+
@approved.approved_at.should_not be_nil
|
71
|
+
@approved.approved_by.should_not be_nil
|
72
|
+
|
73
|
+
@approved.update(:text => 'new text', :current_user => @controller.current_user).should be_false
|
74
|
+
@approved.errors[:invariant].should_not be_nil
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should not update approved on version change' do
|
78
|
+
@approved.version.should_not be_nil
|
79
|
+
@approved.approved_at.should_not be_nil
|
80
|
+
@approved.approved_by.should_not be_nil
|
81
|
+
|
82
|
+
@approved.update(:version => 11, :current_user => @controller.current_user).should be_false
|
83
|
+
@approved.errors[:invariant].should_not be_nil
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should not update approved on code change' do
|
87
|
+
@approved.version.should_not be_nil
|
88
|
+
@approved.approved_at.should_not be_nil
|
89
|
+
@approved.approved_by.should_not be_nil
|
90
|
+
|
91
|
+
@approved.update(:code => "new code", :current_user => @controller.current_user).should be_false
|
92
|
+
@approved.errors[:invariant].should_not be_nil
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should not update on code change' do
|
96
|
+
@text.update(:code => "new code", :current_user => @controller.current_user).should be_false
|
97
|
+
@text.errors[:invariant].should_not be_nil
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should produce xml via the Word model' do
|
101
|
+
text = Ixtlan::Models::I18nText.create(:code => "word", :text => "word text", :current_user => @controller.current_user, :locale => Ixtlan::Models::Locale.default)
|
102
|
+
Ixtlan::Models::Word.first(:code => "word").to_xml.should == "<word><code>word</code><text>word text</text></word>"
|
103
|
+
Ixtlan::Models::Word.all(:id => @approved.id).to_xml(:collection_element_name => "words").should == "<words type='array'><word><code>code</code><text>other text</text></word></words>"
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
|
2
|
+
require 'pathname'
|
3
|
+
require Pathname(__FILE__).dirname + 'spec_helper.rb'
|
4
|
+
|
5
|
+
require 'ixtlan' / 'models' / 'authentication'
|
6
|
+
require 'ixtlan' / 'rails' / 'unrestful_authentication'
|
7
|
+
|
8
|
+
class Controller
|
9
|
+
|
10
|
+
include Ixtlan::Rails::UnrestfulAuthentication
|
11
|
+
|
12
|
+
attr_reader :rendered
|
13
|
+
|
14
|
+
def render_successful_login
|
15
|
+
@rendered = :login
|
16
|
+
end
|
17
|
+
|
18
|
+
def render_access_denied
|
19
|
+
@rendered = :access_denied
|
20
|
+
end
|
21
|
+
|
22
|
+
def render_login_page
|
23
|
+
@rendered = :login_page
|
24
|
+
end
|
25
|
+
|
26
|
+
def render_logout_page
|
27
|
+
@rendered = :logout_page
|
28
|
+
end
|
29
|
+
|
30
|
+
def reset
|
31
|
+
@params.clear
|
32
|
+
@rendered = nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe Ixtlan::Models::Authentication do
|
37
|
+
|
38
|
+
before :all do
|
39
|
+
@controller = Controller.new
|
40
|
+
@log = StringIO.new
|
41
|
+
Slf4r::LoggerFacade4RubyLogger.file = @log
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "login" do
|
45
|
+
|
46
|
+
before :each do
|
47
|
+
@controller.reset
|
48
|
+
@log.reopen
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should show login page' do
|
52
|
+
@controller.send(:authenticate).should be_false
|
53
|
+
@controller.session.empty?.should be_true
|
54
|
+
@controller.rendered.should == :login_page
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should show access denied page - via put' do
|
58
|
+
@controller.request.method = :put
|
59
|
+
@controller.send(:authenticate).should be_false
|
60
|
+
@controller.session.empty?.should be_true
|
61
|
+
@controller.rendered.should == :access_denied
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should show access denied page - via delete' do
|
65
|
+
@controller.request.method = :delete
|
66
|
+
@controller.send(:authenticate).should be_false
|
67
|
+
@controller.session.empty?.should be_true
|
68
|
+
@controller.rendered.should == :access_denied
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should show access denied page - via post - no login - no password' do
|
72
|
+
@controller.request.method = :post
|
73
|
+
@controller.send(:authenticate).should be_false
|
74
|
+
@controller.session.empty?.should be_true
|
75
|
+
@controller.rendered.should == :access_denied
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should show access denied page - via post - no login' do
|
79
|
+
@controller.request.method = :post
|
80
|
+
@controller.params[:password] = @controller.password
|
81
|
+
@controller.send(:authenticate).should be_false
|
82
|
+
@log.string.should =~ /\[\?\?\?\] unknown login from IP/
|
83
|
+
@controller.session.empty?.should be_true
|
84
|
+
@controller.rendered.should == :access_denied
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should show access denied page - via post - no password' do
|
88
|
+
@controller.request.method = :post
|
89
|
+
@controller.params[:login] = @controller.user.login
|
90
|
+
@controller.send(:authenticate).should be_false
|
91
|
+
@log.string.should =~ /\[#{@controller.user.login}\] wrong password from IP/
|
92
|
+
@controller.session.empty?.should be_true
|
93
|
+
@controller.rendered.should == :access_denied
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should login' do
|
97
|
+
@controller.request.method = :post
|
98
|
+
@controller.params[:password] = @controller.password
|
99
|
+
@controller.params[:login] = @controller.user.login
|
100
|
+
@controller.send(:authenticate).should be_false
|
101
|
+
@log.string.should =~ /\[#{@controller.user.login}\] logged in/
|
102
|
+
@controller.session.empty?.should be_false
|
103
|
+
@controller.rendered.should == :login
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe 'logout' do
|
108
|
+
|
109
|
+
before :each do
|
110
|
+
@controller.request.method = :post
|
111
|
+
@controller.params[:password] = @controller.password
|
112
|
+
@controller.params[:login] = @controller.user.login
|
113
|
+
@controller.send :authenticate
|
114
|
+
@controller.reset
|
115
|
+
@log.reopen
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should do nothing' do
|
119
|
+
@controller.request.method = :get
|
120
|
+
@controller.send(:authenticate).should be_true
|
121
|
+
@log.string.should == ''
|
122
|
+
@controller.request.method = :post
|
123
|
+
@controller.send(:authenticate).should be_true
|
124
|
+
@log.string.should == ''
|
125
|
+
@controller.request.method = :put
|
126
|
+
@controller.send(:authenticate).should be_true
|
127
|
+
@log.string.should == ''
|
128
|
+
@controller.request.method = :delete
|
129
|
+
@controller.send(:authenticate).should be_true
|
130
|
+
@log.string.should == ''
|
131
|
+
@controller.rendered.should be_nil
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should logout' do
|
135
|
+
@controller.request.method = :delete
|
136
|
+
@controller.params[:login] = @controller.user.login
|
137
|
+
@controller.send(:authenticate).should be_false
|
138
|
+
@controller.rendered.should == :logout_page
|
139
|
+
@log.string.should =~ /\[#{@controller.user.login}\] logged out/
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require Pathname(__FILE__).dirname + 'spec_helper.rb'
|
3
|
+
|
4
|
+
require 'ixtlan/rails/session_timeout'
|
5
|
+
class Response
|
6
|
+
attr_accessor :content_type
|
7
|
+
def initialize
|
8
|
+
@content_type = ""
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Controller
|
13
|
+
def response
|
14
|
+
@response ||= Response.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe Ixtlan::UserLogger do
|
19
|
+
|
20
|
+
before :all do
|
21
|
+
@controller = Controller.new
|
22
|
+
end
|
23
|
+
|
24
|
+
before :each do
|
25
|
+
@controller.response.content_type = "text/html"
|
26
|
+
@log = StringIO.new
|
27
|
+
Slf4r::LoggerFacade4RubyLogger.file = @log
|
28
|
+
@logger = Ixtlan::UserLogger.new(:root)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should log no user - no message - no block' do
|
32
|
+
@logger.log_user(nil)
|
33
|
+
@log.string.should =~ /\[\?\?\?\]\s*$/
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should log user - no message - no block' do
|
37
|
+
@logger.log_user("user")
|
38
|
+
@log.string.should =~ /\[user\]\s*$/
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should log user - message - no block' do
|
42
|
+
@logger.log_user("user", "message")
|
43
|
+
@log.string.should =~ /\[user\] message\s*$/
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should log user - no message - block' do
|
47
|
+
@logger.log_user("user") { "block" }
|
48
|
+
@log.string.should =~ /\[user\] block\s*$/
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should log - no message - block' do
|
52
|
+
@logger.log(@controller) { "block" }
|
53
|
+
@log.string.should =~ /\[marvin\] block\s*$/
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should log - message - no block' do
|
57
|
+
@logger.log(@controller, "message")
|
58
|
+
@log.string.should =~ /\[marvin\] message\s*$/
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should log - no message - no block' do
|
62
|
+
@logger.log(@controller)
|
63
|
+
@log.string.should =~ /\[marvin\] \s*$/
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should log - no controller - no message - no block' do
|
67
|
+
@logger.log(Object.new)
|
68
|
+
@log.string.should =~ /\[\?\?\?\] \s*$/
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should log action - no resource variable' do
|
72
|
+
@controller.params[:controller] = "resources"
|
73
|
+
@controller.params[:action] = "index"
|
74
|
+
@logger.log_action(@controller)
|
75
|
+
@log.string.should =~ /\[marvin\] resources#index\s*$/
|
76
|
+
|
77
|
+
@controller.response.content_type = "application/xml"
|
78
|
+
@logger.log_action(@controller)
|
79
|
+
@log.string.should =~ /\[marvin\] resources#index - xml\s*$/
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should log action - resource variable' do
|
83
|
+
@controller.params[:controller] = "resources"
|
84
|
+
@controller.params[:action] = "index"
|
85
|
+
@controller.instance_variable_set(:@resource, @controller.current_user.groups[0])
|
86
|
+
@logger.log_action(@controller)
|
87
|
+
@log.string.should =~ /\[marvin\] resources#index .*Group\([0-9]\)\s*$/
|
88
|
+
@controller.response.content_type = "application/xml"
|
89
|
+
@logger.log_action(@controller)
|
90
|
+
@log.string.should =~ /\[marvin\] resources#index .*Group\([0-9]\) - xml\s*$/
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should log action - resources variable' do
|
94
|
+
@controller.params[:controller] = "resources"
|
95
|
+
@controller.params[:action] = "index"
|
96
|
+
@controller.instance_variable_set(:@resources, @controller.current_user.groups)
|
97
|
+
size = @controller.current_user.groups.size
|
98
|
+
@logger.log_action(@controller)
|
99
|
+
@log.string.should =~ /\[marvin\] resources#index .*Groups\[#{size}\]\s*$/
|
100
|
+
@controller.response.content_type = "application/xml"
|
101
|
+
@logger.log_action(@controller)
|
102
|
+
@log.string.should =~ /\[marvin\] resources#index .*Groups\[#{size}\] - xml\s*$/
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|