typus 0.9.17

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.
Files changed (154) hide show
  1. data/.gitignore +8 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +86 -0
  4. data/Rakefile +61 -0
  5. data/VERSION +1 -0
  6. data/app/controllers/admin/master_controller.rb +354 -0
  7. data/app/controllers/typus_controller.rb +128 -0
  8. data/app/helpers/admin/form_helper.rb +386 -0
  9. data/app/helpers/admin/master_helper.rb +104 -0
  10. data/app/helpers/admin/public_helper.rb +27 -0
  11. data/app/helpers/admin/sidebar_helper.rb +236 -0
  12. data/app/helpers/admin/table_helper.rb +227 -0
  13. data/app/helpers/typus_helper.rb +194 -0
  14. data/app/models/typus_mailer.rb +14 -0
  15. data/app/models/typus_user.rb +5 -0
  16. data/app/views/admin/dashboard/_sidebar.html.erb +9 -0
  17. data/app/views/admin/resources/edit.html.erb +24 -0
  18. data/app/views/admin/resources/index.html.erb +23 -0
  19. data/app/views/admin/resources/new.html.erb +22 -0
  20. data/app/views/admin/resources/show.html.erb +18 -0
  21. data/app/views/admin/shared/_footer.html.erb +1 -0
  22. data/app/views/admin/shared/_pagination.html.erb +28 -0
  23. data/app/views/layouts/admin.html.erb +73 -0
  24. data/app/views/layouts/typus.html.erb +29 -0
  25. data/app/views/typus/dashboard.html.erb +9 -0
  26. data/app/views/typus/recover_password.html.erb +7 -0
  27. data/app/views/typus/reset_password.html.erb +15 -0
  28. data/app/views/typus/sign_in.html.erb +9 -0
  29. data/app/views/typus/sign_up.html.erb +7 -0
  30. data/app/views/typus_mailer/reset_password_link.erb +11 -0
  31. data/config/locales/typus/de.yml +109 -0
  32. data/config/locales/typus/es.yml +109 -0
  33. data/config/locales/typus/language.yml.template +113 -0
  34. data/config/locales/typus/pt-BR.yml +111 -0
  35. data/config/locales/typus/ru.yml +111 -0
  36. data/generators/typus/templates/config/initializers/typus.rb +33 -0
  37. data/generators/typus/templates/config/typus/README +51 -0
  38. data/generators/typus/templates/config/typus/application.yml +6 -0
  39. data/generators/typus/templates/config/typus/application_roles.yml +23 -0
  40. data/generators/typus/templates/config/typus/typus.yml +14 -0
  41. data/generators/typus/templates/config/typus/typus_roles.yml +2 -0
  42. data/generators/typus/templates/db/create_typus_users.rb +21 -0
  43. data/generators/typus/templates/public/images/admin/arrow_down.gif +0 -0
  44. data/generators/typus/templates/public/images/admin/arrow_up.gif +0 -0
  45. data/generators/typus/templates/public/images/admin/spinner.gif +0 -0
  46. data/generators/typus/templates/public/images/admin/status_false.gif +0 -0
  47. data/generators/typus/templates/public/images/admin/status_true.gif +0 -0
  48. data/generators/typus/templates/public/images/admin/trash.gif +0 -0
  49. data/generators/typus/templates/public/javascripts/admin/application.js +14 -0
  50. data/generators/typus/templates/public/stylesheets/admin/reset.css +68 -0
  51. data/generators/typus/templates/public/stylesheets/admin/screen.css +729 -0
  52. data/generators/typus/typus_generator.rb +122 -0
  53. data/generators/typus_update_schema_to_01/templates/config/typus.yml +14 -0
  54. data/generators/typus_update_schema_to_01/templates/migration.rb +11 -0
  55. data/generators/typus_update_schema_to_01/typus_update_schema_to_01_generator.rb +19 -0
  56. data/lib/typus.rb +122 -0
  57. data/lib/typus/active_record.rb +307 -0
  58. data/lib/typus/authentication.rb +142 -0
  59. data/lib/typus/configuration.rb +85 -0
  60. data/lib/typus/extensions/routes.rb +15 -0
  61. data/lib/typus/format.rb +55 -0
  62. data/lib/typus/generator.rb +81 -0
  63. data/lib/typus/hash.rb +8 -0
  64. data/lib/typus/locale.rb +17 -0
  65. data/lib/typus/object.rb +21 -0
  66. data/lib/typus/quick_edit.rb +40 -0
  67. data/lib/typus/reloader.rb +15 -0
  68. data/lib/typus/string.rb +11 -0
  69. data/lib/typus/templates/index.html.erb +11 -0
  70. data/lib/typus/templates/resource_controller.rb.erb +15 -0
  71. data/lib/typus/templates/resource_controller_test.rb.erb +10 -0
  72. data/lib/typus/templates/resources_controller.rb.erb +37 -0
  73. data/lib/typus/user.rb +134 -0
  74. data/lib/vendor/active_record.rb +15 -0
  75. data/lib/vendor/paginator.rb +143 -0
  76. data/rails/init.rb +3 -0
  77. data/tasks/typus_tasks.rake +32 -0
  78. data/test/config/broken/application.yml +68 -0
  79. data/test/config/broken/application_roles.yml +20 -0
  80. data/test/config/broken/empty.yml +0 -0
  81. data/test/config/broken/empty_roles.yml +0 -0
  82. data/test/config/broken/undefined.yml +3 -0
  83. data/test/config/broken/undefined_roles.yml +6 -0
  84. data/test/config/default/typus.yml +14 -0
  85. data/test/config/default/typus_roles.yml +2 -0
  86. data/test/config/empty/empty_01.yml +0 -0
  87. data/test/config/empty/empty_01_roles.yml +0 -0
  88. data/test/config/empty/empty_02.yml +0 -0
  89. data/test/config/empty/empty_02_roles.yml +0 -0
  90. data/test/config/locales/es.yml +10 -0
  91. data/test/config/ordered/001_roles.yml +2 -0
  92. data/test/config/ordered/002_roles.yml +2 -0
  93. data/test/config/unordered/app_one_roles.yml +2 -0
  94. data/test/config/unordered/app_two_roles.yml +2 -0
  95. data/test/config/working/application.yml +68 -0
  96. data/test/config/working/application_roles.yml +22 -0
  97. data/test/config/working/typus.yml +14 -0
  98. data/test/config/working/typus_roles.yml +2 -0
  99. data/test/fixtures/app/controllers/admin/assets_controller.rb +2 -0
  100. data/test/fixtures/app/controllers/admin/categories_controller.rb +2 -0
  101. data/test/fixtures/app/controllers/admin/comments_controller.rb +2 -0
  102. data/test/fixtures/app/controllers/admin/pages_controller.rb +2 -0
  103. data/test/fixtures/app/controllers/admin/posts_controller.rb +2 -0
  104. data/test/fixtures/app/controllers/admin/status_controller.rb +6 -0
  105. data/test/fixtures/app/controllers/admin/typus_users_controller.rb +2 -0
  106. data/test/fixtures/app/controllers/admin/watch_dog_controller.rb +6 -0
  107. data/test/fixtures/app/views/admin/comments/_edit.html.erb +1 -0
  108. data/test/fixtures/app/views/admin/comments/_index.html.erb +1 -0
  109. data/test/fixtures/app/views/admin/comments/_new.html.erb +1 -0
  110. data/test/fixtures/app/views/admin/comments/_show.html.erb +1 -0
  111. data/test/fixtures/app/views/admin/comments/_sidebar.html.erb +1 -0
  112. data/test/fixtures/app/views/admin/dashboard/_content.html.erb +1 -0
  113. data/test/fixtures/app/views/admin/dashboard/_sidebar.html.erb +1 -0
  114. data/test/fixtures/app/views/admin/resources/_sidebar.html.erb +1 -0
  115. data/test/fixtures/app/views/admin/shared/_footer.html.erb +1 -0
  116. data/test/fixtures/app/views/admin/status/index.html.erb +1 -0
  117. data/test/fixtures/app/views/admin/templates/_datepicker.html.erb +1 -0
  118. data/test/fixtures/assets.yml +11 -0
  119. data/test/fixtures/categories.yml +14 -0
  120. data/test/fixtures/comments.yml +27 -0
  121. data/test/fixtures/pages.yml +41 -0
  122. data/test/fixtures/posts.yml +37 -0
  123. data/test/fixtures/typus_users.yml +54 -0
  124. data/test/functional/admin/assets_controller_test.rb +57 -0
  125. data/test/functional/admin/categories_controller_test.rb +106 -0
  126. data/test/functional/admin/comments_controller_test.rb +120 -0
  127. data/test/functional/admin/master_controller_test.rb +5 -0
  128. data/test/functional/admin/posts_controller_test.rb +261 -0
  129. data/test/functional/admin/status_controller_test.rb +43 -0
  130. data/test/functional/admin/typus_users_controller_test.rb +239 -0
  131. data/test/functional/typus_controller_test.rb +321 -0
  132. data/test/helper.rb +51 -0
  133. data/test/helpers/admin/form_helper_test.rb +337 -0
  134. data/test/helpers/admin/master_helper_test.rb +69 -0
  135. data/test/helpers/admin/public_helper_test.rb +26 -0
  136. data/test/helpers/admin/sidebar_helper_test.rb +335 -0
  137. data/test/helpers/admin/table_helper_test.rb +239 -0
  138. data/test/helpers/typus_helper_test.rb +117 -0
  139. data/test/lib/active_record_test.rb +382 -0
  140. data/test/lib/configuration_test.rb +94 -0
  141. data/test/lib/hash_test.rb +11 -0
  142. data/test/lib/routes_test.rb +71 -0
  143. data/test/lib/string_test.rb +25 -0
  144. data/test/lib/typus_test.rb +85 -0
  145. data/test/models.rb +51 -0
  146. data/test/schema.rb +64 -0
  147. data/test/unit/typus_mailer_test.rb +33 -0
  148. data/test/unit/typus_test.rb +17 -0
  149. data/test/unit/typus_user_roles_test.rb +90 -0
  150. data/test/unit/typus_user_test.rb +177 -0
  151. data/test/vendor/active_record_test.rb +18 -0
  152. data/test/vendor/paginator_test.rb +136 -0
  153. data/typus.gemspec +228 -0
  154. metadata +241 -0
@@ -0,0 +1,90 @@
1
+ require 'test/helper'
2
+
3
+ class TypusUserRolesTest < ActiveSupport::TestCase
4
+
5
+ def test_should_get_list_of_roles
6
+ roles = %w( admin designer editor )
7
+ assert_equal roles, Typus::Configuration.roles.map(&:first).sort
8
+ end
9
+
10
+ def test_admin_role_settings
11
+
12
+ typus_user = typus_users(:admin)
13
+ assert_equal 'admin', typus_user.role
14
+
15
+ models = %w( Asset Category Comment Git Page Post Status TypusUser WatchDog )
16
+ assert_equal models, typus_user.resources.map(&:first).sort
17
+
18
+ # Order exists on the roles, but, as we compact the hash, the
19
+ # resource is removed.
20
+ assert !typus_user.resources.map(&:first).include?('Order')
21
+
22
+ resources = %w( Git Status WatchDog )
23
+ models.delete_if { |m| resources.include?(m) }
24
+
25
+ %w( create read update destroy ).each do |action|
26
+ models.each { |model| assert typus_user.can_perform?(model, action) }
27
+ end
28
+
29
+ # Order resource doesn't have an index action, so we current user
30
+ # cannot perform the action.
31
+ assert !typus_user.can_perform?('Order', 'index')
32
+
33
+ # Status resource has an index action, but not a show one.
34
+ # We add the { :special => true } option to by-pass the action
35
+ # renaming performed in the TypusUser#can_perform? method.
36
+ assert typus_user.can_perform?('Status', 'index', { :special => true })
37
+ assert !typus_user.can_perform?('Status', 'show', { :special => true })
38
+
39
+ end
40
+
41
+ def test_editor_role_settings
42
+
43
+ typus_user = typus_users(:editor)
44
+ assert_equal 'editor', typus_user.role
45
+
46
+ %w( Category Comment Git Post TypusUser ).each do |model|
47
+ assert typus_user.resources.map(&:first).include?(model)
48
+ end
49
+
50
+ # Category: create, read, update
51
+ %w( create read update ).each { |action| assert typus_user.can_perform?('Category', action) }
52
+ %w( delete ).each { |action| assert !typus_user.can_perform?('Category', action) }
53
+
54
+ # Post: create, read, update
55
+ %w( create read update ).each { |action| assert typus_user.can_perform?('Post', action) }
56
+ %w( delete ).each { |action| assert !typus_user.can_perform?('Post', action) }
57
+
58
+ # Comment: read, update, delete
59
+ %w( read update delete ).each { |action| assert typus_user.can_perform?('Comment', action) }
60
+ %w( create ).each { |action| assert !typus_user.can_perform?('Comment', action) }
61
+
62
+ # TypusUser: read, update
63
+ %w( read update ).each { |action| assert typus_user.can_perform?('TypusUser', action) }
64
+ %w( create delete ).each { |action| assert !typus_user.can_perform?('TypusUser', action) }
65
+
66
+ end
67
+
68
+ def test_designer_role_settings
69
+
70
+ typus_user = typus_users(:designer)
71
+ assert_equal 'designer', typus_user.role
72
+
73
+ models = %w( Category Comment Post )
74
+ assert_equal models, typus_user.resources.map(&:first).sort
75
+
76
+ # Category: read, update
77
+ %w( read update ).each { |action| assert typus_user.can_perform?('Category', action) }
78
+ %w( create delete ).each { |action| assert !typus_user.can_perform?('Category', action) }
79
+
80
+ # Comment: read
81
+ %w( read ).each { |action| assert typus_user.can_perform?('Comment', action) }
82
+ %w( create update delete ).each { |action| assert !typus_user.can_perform?('Comment', action) }
83
+
84
+ # Post: read
85
+ %w( read ).each { |action| assert typus_user.can_perform?('Post', action) }
86
+ %w( create update delete ).each { |action| assert !typus_user.can_perform?('Post', action) }
87
+
88
+ end
89
+
90
+ end
@@ -0,0 +1,177 @@
1
+ require 'test/helper'
2
+
3
+ class TypusUserTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ @data = { :first_name => '',
7
+ :last_name => '',
8
+ :email => 'test@example.com',
9
+ :password => '12345678',
10
+ :password_confirmation => '12345678',
11
+ :role => Typus::Configuration.options[:root] }
12
+ @typus_user = TypusUser.new(@data)
13
+ end
14
+
15
+ def test_should_verify_typus_user_attributes
16
+ %w( first_name last_name email role salt crypted_password ).each do |attribute|
17
+ assert TypusUser.instance_methods.include?(attribute)
18
+ end
19
+ end
20
+
21
+ def test_should_verify_definition_on_instance_methods
22
+ %w( is_root? authenticated? ).each do |instance_method|
23
+ assert TypusUser.instance_methods.include?(instance_method)
24
+ end
25
+ end
26
+
27
+ def test_should_verify_email_format
28
+ @typus_user.email = 'admin'
29
+ assert @typus_user.invalid?
30
+ assert @typus_user.errors.invalid?(:email)
31
+ end
32
+
33
+ def test_should_verify_email_is_not_valid
34
+ email = <<-RAW
35
+ this_is_chelm@example.com
36
+ <script>location.href="http://spammersite.com"</script>
37
+ RAW
38
+ @typus_user.email = email
39
+ assert @typus_user.invalid?
40
+ assert @typus_user.errors.invalid?(:email)
41
+ end
42
+
43
+ def test_should_verify_emails_are_downcase
44
+ email = 'TEST@EXAMPLE.COM'
45
+ @typus_user.email = email
46
+ assert @typus_user.invalid?
47
+ assert @typus_user.errors.invalid?(:email)
48
+ end
49
+
50
+ def test_should_verify_some_valid_emails_schemas
51
+ emails = [ 'test+filter@example.com',
52
+ 'test.filter@example.com',
53
+ 'test@example.co.uk',
54
+ 'test@example.es' ]
55
+ emails.each do |email|
56
+ @typus_user.email = email
57
+ assert @typus_user.valid?
58
+ end
59
+ end
60
+
61
+ def test_should_verify_invalid_emails_are_detected
62
+ emails = [ 'test@example', 'test@example.c', 'testexample.com' ]
63
+ emails.each do |email|
64
+ @typus_user.email = email
65
+ assert @typus_user.invalid?
66
+ assert @typus_user.errors.invalid?(:email)
67
+ end
68
+ end
69
+
70
+ def test_should_verify_email_is_unique
71
+ @typus_user.save
72
+ @another_typus_user = TypusUser.new(@data)
73
+ assert @another_typus_user.invalid?
74
+ assert @another_typus_user.errors.invalid?(:email)
75
+ end
76
+
77
+ def test_should_verify_length_of_password_when_under_within
78
+ @typus_user.password = '1234'
79
+ @typus_user.password_confirmation = '1234'
80
+ assert @typus_user.invalid?
81
+ assert @typus_user.errors.invalid?(:password)
82
+ end
83
+
84
+ def test_should_verify_length_of_password_when_its_within_on_lower_limit
85
+ @typus_user.password = '=' * 8
86
+ @typus_user.password_confirmation = '=' * 8
87
+ assert @typus_user.valid?
88
+ end
89
+
90
+ def test_should_verify_length_of_password_when_its_within_on_upper_limit
91
+ @typus_user.password = '=' * 40
92
+ @typus_user.password_confirmation = '=' * 40
93
+ assert @typus_user.valid?
94
+ end
95
+
96
+ def test_should_verify_length_of_password_when_its_over_within
97
+ @typus_user.password = '=' * 50
98
+ @typus_user.password_confirmation = '=' * 50
99
+ assert @typus_user.invalid?
100
+ assert @typus_user.errors.invalid?(:password)
101
+ end
102
+
103
+ def test_should_verify_confirmation_of_password
104
+
105
+ @typus_user.password = '12345678'
106
+ @typus_user.password_confirmation = '87654321'
107
+ assert @typus_user.invalid?
108
+ assert @typus_user.errors.invalid?(:password)
109
+
110
+ @typus_user.password = '12345678'
111
+ @typus_user.password_confirmation = ''
112
+ assert @typus_user.invalid?
113
+ assert @typus_user.errors.invalid?(:password)
114
+
115
+ end
116
+
117
+ def test_should_verify_role
118
+ @typus_user.role = ''
119
+ assert @typus_user.invalid?
120
+ assert @typus_user.errors.invalid?(:role)
121
+ assert_equal "can't be blank", @typus_user.errors[:role]
122
+ end
123
+
124
+ def test_should_return_name_when_only_email
125
+ assert_equal @typus_user.email, @typus_user.name
126
+ end
127
+
128
+ def test_should_return_name_when_theres_first_name_and_last_name
129
+ @typus_user.first_name = 'John'
130
+ @typus_user.last_name = 'Smith'
131
+ assert_equal 'John Smith', @typus_user.name
132
+ end
133
+
134
+ def test_should_return_verify_is_root
135
+ assert @typus_user.is_root?
136
+ editor = typus_users(:editor)
137
+ assert !editor.is_root?
138
+ end
139
+
140
+ def test_should_verify_authenticated
141
+ @typus_user.save
142
+ assert @typus_user.authenticated?('12345678')
143
+ assert !@typus_user.authenticated?('87654321')
144
+ end
145
+
146
+ def test_should_verify_typus_user_can_be_created
147
+ assert_difference 'TypusUser.count' do
148
+ TypusUser.create(@data)
149
+ end
150
+ end
151
+
152
+ def test_should_verify_salt_on_user_never_changes
153
+
154
+ @typus_user.save
155
+ salt = @typus_user.salt
156
+ crypted_password = @typus_user.crypted_password
157
+
158
+ @typus_user.update_attributes :password => '11111111', :password_confirmation => '11111111'
159
+ assert_equal salt, @typus_user.salt
160
+ assert_not_equal crypted_password, @typus_user.crypted_password
161
+
162
+ end
163
+
164
+ def test_should_verify_generate
165
+ assert TypusUser.respond_to?(:generate)
166
+ assert TypusUser.generate('demo@example.com', 'XXXXXXXX').valid?
167
+ assert TypusUser.generate('demo@example.com', 'XXXX').invalid?
168
+ end
169
+
170
+ def test_should_verify_can_perform?
171
+ assert TypusUser.instance_methods.include?('can_perform?')
172
+ @current_user = TypusUser.find(:first)
173
+ assert @current_user.can_perform?(TypusUser, 'delete')
174
+ assert @current_user.can_perform?('TypusUser', 'delete')
175
+ end
176
+
177
+ end
@@ -0,0 +1,18 @@
1
+ require 'test/helper'
2
+
3
+ class ActiveRecordTest < ActiveSupport::TestCase
4
+
5
+ def test_should_verify_to_dom
6
+
7
+ assert_equal "typus_user_new", TypusUser.new.to_dom
8
+
9
+ typus_user = typus_users(:admin)
10
+ assert_equal "typus_user_#{typus_user.id}", typus_user.to_dom
11
+
12
+ assert_equal "prefix_typus_user_#{typus_user.id}", typus_user.to_dom(:prefix => 'prefix')
13
+ assert_equal "typus_user_#{typus_user.id}_suffix", typus_user.to_dom(:suffix => 'suffix')
14
+ assert_equal "prefix_typus_user_#{typus_user.id}_suffix", typus_user.to_dom(:prefix => 'prefix', :suffix => 'suffix')
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,136 @@
1
+ require 'test/helper'
2
+
3
+ class PaginatorTest < ActiveSupport::TestCase
4
+
5
+ PER_PAGE = 10
6
+
7
+ def setup
8
+ @data = (0..43).to_a
9
+ @pager = Paginator.new(@data.size, PER_PAGE) do |offset,per_page|
10
+ @data[offset,per_page]
11
+ end
12
+ end
13
+
14
+ def test_initializing_paginator_raises_exception
15
+ assert_raises(Paginator::MissingSelectError) do
16
+ @pager = Paginator.new(@data.size, PER_PAGE)
17
+ end
18
+ end
19
+
20
+ def test_can_get_last_page_from_page_object
21
+ assert_equal @pager.last, @pager.page(2).last
22
+ end
23
+
24
+ def test_can_get_first_page_from_page_object
25
+ assert_equal @pager.first, @pager.page(2).first
26
+ end
27
+
28
+ def test_does_not_exceed_per_page
29
+ @pager.each do |page|
30
+ assert page.items.size <= PER_PAGE
31
+ end
32
+ end
33
+
34
+ def test_only_last_page_has_less_items
35
+ @pager.each do |page|
36
+ if page != @pager.last
37
+ assert page.items.size <= PER_PAGE
38
+ else
39
+ assert page.items.size < PER_PAGE
40
+ end
41
+ end
42
+ end
43
+
44
+ def test_returns_correct_first_page
45
+ assert_equal @pager.page(1).number, @pager.first.number
46
+ end
47
+
48
+ def test_returns_correct_last_page
49
+ assert_equal @pager.page(5).number, @pager.last.number
50
+ end
51
+
52
+ def test_last_page_has_no_next_page
53
+ assert !@pager.last.next?
54
+ assert !@pager.last.next
55
+ end
56
+
57
+ def test_first_page_has_no_prev_page
58
+ assert !@pager.first.prev?
59
+ assert !@pager.first.prev
60
+ end
61
+
62
+ def test_page_enumerable
63
+ @pager.each do |page|
64
+ assert page
65
+ page.each do |item|
66
+ assert item
67
+ end
68
+ page.each_with_index do |item, index|
69
+ assert_equal page.items[index], item
70
+ end
71
+ assert_equal page.items, page.inject([]) {|list, item| list << item }
72
+ end
73
+ end
74
+
75
+ def test_each_with_index
76
+ page_offset = 0
77
+ @pager.each_with_index do |page, page_index|
78
+ assert page
79
+ assert_equal page_offset, page_index
80
+ item_offset = 0
81
+ page.each_with_index do |item, item_index|
82
+ assert item
83
+ assert_equal item_offset, item_index
84
+ item_offset += 1
85
+ end
86
+ page_offset += 1
87
+ end
88
+ end
89
+
90
+ def test_number_of_pages
91
+ assert_equal 5, @pager.number_of_pages
92
+ end
93
+
94
+ def test_passing_block_to_initializer_with_arity_of_two_yields_per_page
95
+ pager = Paginator.new(20,2) do |offset,per_page|
96
+ assert_equal 2, per_page
97
+ end
98
+ pager.page(1).items
99
+ end
100
+
101
+ def test_passing_block_to_initializer_with_arity_of_one_does_not_yield_per_page
102
+ pager = Paginator.new(20,2) do |offset|
103
+ assert_equal 0, offset
104
+ end
105
+ pager.page(1).items
106
+ end
107
+
108
+ def test_page_object_knows_first_and_last_item_numbers
109
+ items = (1..11).to_a
110
+ pager = Paginator.new(items.size,3) do |offset, per_page|
111
+ items[offset, per_page]
112
+ end
113
+ page = pager.page(1)
114
+ assert_equal 1, page.first_item_number
115
+ assert_equal 3, page.last_item_number
116
+ page = pager.page(2)
117
+ assert_equal 4, page.first_item_number
118
+ assert_equal 6, page.last_item_number
119
+ page = pager.page(3)
120
+ assert_equal 7, page.first_item_number
121
+ assert_equal 9, page.last_item_number
122
+ page = pager.page(4)
123
+ assert_equal 10, page.first_item_number
124
+ assert_equal 11, page.last_item_number
125
+ end
126
+
127
+ end
128
+
129
+ class PaginatorTestWithMathN < PaginatorTest
130
+
131
+ def setup
132
+ require 'mathn'
133
+ super
134
+ end
135
+
136
+ end
data/typus.gemspec ADDED
@@ -0,0 +1,228 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{typus}
8
+ s.version = "0.9.17"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Francesc Esplugas"]
12
+ s.date = %q{2009-08-18}
13
+ s.description = %q{Effortless backend interface for Ruby on Rails applications. (Admin scaffold generator.)}
14
+ s.email = %q{francesc@intraducibles.com}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "app/controllers/admin/master_controller.rb",
25
+ "app/controllers/typus_controller.rb",
26
+ "app/helpers/admin/form_helper.rb",
27
+ "app/helpers/admin/master_helper.rb",
28
+ "app/helpers/admin/public_helper.rb",
29
+ "app/helpers/admin/sidebar_helper.rb",
30
+ "app/helpers/admin/table_helper.rb",
31
+ "app/helpers/typus_helper.rb",
32
+ "app/models/typus_mailer.rb",
33
+ "app/models/typus_user.rb",
34
+ "app/views/admin/dashboard/_sidebar.html.erb",
35
+ "app/views/admin/resources/edit.html.erb",
36
+ "app/views/admin/resources/index.html.erb",
37
+ "app/views/admin/resources/new.html.erb",
38
+ "app/views/admin/resources/show.html.erb",
39
+ "app/views/admin/shared/_footer.html.erb",
40
+ "app/views/admin/shared/_pagination.html.erb",
41
+ "app/views/layouts/admin.html.erb",
42
+ "app/views/layouts/typus.html.erb",
43
+ "app/views/typus/dashboard.html.erb",
44
+ "app/views/typus/recover_password.html.erb",
45
+ "app/views/typus/reset_password.html.erb",
46
+ "app/views/typus/sign_in.html.erb",
47
+ "app/views/typus/sign_up.html.erb",
48
+ "app/views/typus_mailer/reset_password_link.erb",
49
+ "config/locales/typus/de.yml",
50
+ "config/locales/typus/es.yml",
51
+ "config/locales/typus/language.yml.template",
52
+ "config/locales/typus/pt-BR.yml",
53
+ "config/locales/typus/ru.yml",
54
+ "generators/typus/templates/config/initializers/typus.rb",
55
+ "generators/typus/templates/config/typus/README",
56
+ "generators/typus/templates/config/typus/application.yml",
57
+ "generators/typus/templates/config/typus/application_roles.yml",
58
+ "generators/typus/templates/config/typus/typus.yml",
59
+ "generators/typus/templates/config/typus/typus_roles.yml",
60
+ "generators/typus/templates/db/create_typus_users.rb",
61
+ "generators/typus/templates/public/images/admin/arrow_down.gif",
62
+ "generators/typus/templates/public/images/admin/arrow_up.gif",
63
+ "generators/typus/templates/public/images/admin/spinner.gif",
64
+ "generators/typus/templates/public/images/admin/status_false.gif",
65
+ "generators/typus/templates/public/images/admin/status_true.gif",
66
+ "generators/typus/templates/public/images/admin/trash.gif",
67
+ "generators/typus/templates/public/javascripts/admin/application.js",
68
+ "generators/typus/templates/public/stylesheets/admin/reset.css",
69
+ "generators/typus/templates/public/stylesheets/admin/screen.css",
70
+ "generators/typus/typus_generator.rb",
71
+ "generators/typus_update_schema_to_01/templates/config/typus.yml",
72
+ "generators/typus_update_schema_to_01/templates/migration.rb",
73
+ "generators/typus_update_schema_to_01/typus_update_schema_to_01_generator.rb",
74
+ "lib/typus.rb",
75
+ "lib/typus/active_record.rb",
76
+ "lib/typus/authentication.rb",
77
+ "lib/typus/configuration.rb",
78
+ "lib/typus/extensions/routes.rb",
79
+ "lib/typus/format.rb",
80
+ "lib/typus/generator.rb",
81
+ "lib/typus/hash.rb",
82
+ "lib/typus/locale.rb",
83
+ "lib/typus/object.rb",
84
+ "lib/typus/quick_edit.rb",
85
+ "lib/typus/reloader.rb",
86
+ "lib/typus/string.rb",
87
+ "lib/typus/templates/index.html.erb",
88
+ "lib/typus/templates/resource_controller.rb.erb",
89
+ "lib/typus/templates/resource_controller_test.rb.erb",
90
+ "lib/typus/templates/resources_controller.rb.erb",
91
+ "lib/typus/user.rb",
92
+ "lib/vendor/active_record.rb",
93
+ "lib/vendor/paginator.rb",
94
+ "rails/init.rb",
95
+ "tasks/typus_tasks.rake",
96
+ "test/config/broken/application.yml",
97
+ "test/config/broken/application_roles.yml",
98
+ "test/config/broken/empty.yml",
99
+ "test/config/broken/empty_roles.yml",
100
+ "test/config/broken/undefined.yml",
101
+ "test/config/broken/undefined_roles.yml",
102
+ "test/config/default/typus.yml",
103
+ "test/config/default/typus_roles.yml",
104
+ "test/config/empty/empty_01.yml",
105
+ "test/config/empty/empty_01_roles.yml",
106
+ "test/config/empty/empty_02.yml",
107
+ "test/config/empty/empty_02_roles.yml",
108
+ "test/config/locales/es.yml",
109
+ "test/config/ordered/001_roles.yml",
110
+ "test/config/ordered/002_roles.yml",
111
+ "test/config/unordered/app_one_roles.yml",
112
+ "test/config/unordered/app_two_roles.yml",
113
+ "test/config/working/application.yml",
114
+ "test/config/working/application_roles.yml",
115
+ "test/config/working/typus.yml",
116
+ "test/config/working/typus_roles.yml",
117
+ "test/fixtures/app/controllers/admin/assets_controller.rb",
118
+ "test/fixtures/app/controllers/admin/categories_controller.rb",
119
+ "test/fixtures/app/controllers/admin/comments_controller.rb",
120
+ "test/fixtures/app/controllers/admin/pages_controller.rb",
121
+ "test/fixtures/app/controllers/admin/posts_controller.rb",
122
+ "test/fixtures/app/controllers/admin/status_controller.rb",
123
+ "test/fixtures/app/controllers/admin/typus_users_controller.rb",
124
+ "test/fixtures/app/controllers/admin/watch_dog_controller.rb",
125
+ "test/fixtures/app/views/admin/comments/_edit.html.erb",
126
+ "test/fixtures/app/views/admin/comments/_index.html.erb",
127
+ "test/fixtures/app/views/admin/comments/_new.html.erb",
128
+ "test/fixtures/app/views/admin/comments/_show.html.erb",
129
+ "test/fixtures/app/views/admin/comments/_sidebar.html.erb",
130
+ "test/fixtures/app/views/admin/dashboard/_content.html.erb",
131
+ "test/fixtures/app/views/admin/dashboard/_sidebar.html.erb",
132
+ "test/fixtures/app/views/admin/resources/_sidebar.html.erb",
133
+ "test/fixtures/app/views/admin/shared/_footer.html.erb",
134
+ "test/fixtures/app/views/admin/status/index.html.erb",
135
+ "test/fixtures/app/views/admin/templates/_datepicker.html.erb",
136
+ "test/fixtures/assets.yml",
137
+ "test/fixtures/categories.yml",
138
+ "test/fixtures/comments.yml",
139
+ "test/fixtures/pages.yml",
140
+ "test/fixtures/posts.yml",
141
+ "test/fixtures/typus_users.yml",
142
+ "test/functional/admin/assets_controller_test.rb",
143
+ "test/functional/admin/categories_controller_test.rb",
144
+ "test/functional/admin/comments_controller_test.rb",
145
+ "test/functional/admin/master_controller_test.rb",
146
+ "test/functional/admin/posts_controller_test.rb",
147
+ "test/functional/admin/status_controller_test.rb",
148
+ "test/functional/admin/typus_users_controller_test.rb",
149
+ "test/functional/typus_controller_test.rb",
150
+ "test/helper.rb",
151
+ "test/helpers/admin/form_helper_test.rb",
152
+ "test/helpers/admin/master_helper_test.rb",
153
+ "test/helpers/admin/public_helper_test.rb",
154
+ "test/helpers/admin/sidebar_helper_test.rb",
155
+ "test/helpers/admin/table_helper_test.rb",
156
+ "test/helpers/typus_helper_test.rb",
157
+ "test/lib/active_record_test.rb",
158
+ "test/lib/configuration_test.rb",
159
+ "test/lib/hash_test.rb",
160
+ "test/lib/routes_test.rb",
161
+ "test/lib/string_test.rb",
162
+ "test/lib/typus_test.rb",
163
+ "test/models.rb",
164
+ "test/schema.rb",
165
+ "test/unit/typus_mailer_test.rb",
166
+ "test/unit/typus_test.rb",
167
+ "test/unit/typus_user_roles_test.rb",
168
+ "test/unit/typus_user_test.rb",
169
+ "test/vendor/active_record_test.rb",
170
+ "test/vendor/paginator_test.rb",
171
+ "typus.gemspec"
172
+ ]
173
+ s.has_rdoc = true
174
+ s.homepage = %q{http://intraducibles.com/projects/typus}
175
+ s.rdoc_options = ["--charset=UTF-8"]
176
+ s.require_paths = ["lib"]
177
+ s.rubygems_version = %q{1.3.1}
178
+ s.summary = %q{Effortless backend interface for Ruby on Rails applications. (Admin scaffold generator.)}
179
+ s.test_files = [
180
+ "test/fixtures/app/controllers/admin/assets_controller.rb",
181
+ "test/fixtures/app/controllers/admin/categories_controller.rb",
182
+ "test/fixtures/app/controllers/admin/comments_controller.rb",
183
+ "test/fixtures/app/controllers/admin/pages_controller.rb",
184
+ "test/fixtures/app/controllers/admin/posts_controller.rb",
185
+ "test/fixtures/app/controllers/admin/status_controller.rb",
186
+ "test/fixtures/app/controllers/admin/typus_users_controller.rb",
187
+ "test/fixtures/app/controllers/admin/watch_dog_controller.rb",
188
+ "test/functional/admin/assets_controller_test.rb",
189
+ "test/functional/admin/categories_controller_test.rb",
190
+ "test/functional/admin/comments_controller_test.rb",
191
+ "test/functional/admin/master_controller_test.rb",
192
+ "test/functional/admin/posts_controller_test.rb",
193
+ "test/functional/admin/status_controller_test.rb",
194
+ "test/functional/admin/typus_users_controller_test.rb",
195
+ "test/functional/typus_controller_test.rb",
196
+ "test/helper.rb",
197
+ "test/helpers/admin/form_helper_test.rb",
198
+ "test/helpers/admin/master_helper_test.rb",
199
+ "test/helpers/admin/public_helper_test.rb",
200
+ "test/helpers/admin/sidebar_helper_test.rb",
201
+ "test/helpers/admin/table_helper_test.rb",
202
+ "test/helpers/typus_helper_test.rb",
203
+ "test/lib/active_record_test.rb",
204
+ "test/lib/configuration_test.rb",
205
+ "test/lib/hash_test.rb",
206
+ "test/lib/routes_test.rb",
207
+ "test/lib/string_test.rb",
208
+ "test/lib/typus_test.rb",
209
+ "test/models.rb",
210
+ "test/schema.rb",
211
+ "test/unit/typus_mailer_test.rb",
212
+ "test/unit/typus_test.rb",
213
+ "test/unit/typus_user_roles_test.rb",
214
+ "test/unit/typus_user_test.rb",
215
+ "test/vendor/active_record_test.rb",
216
+ "test/vendor/paginator_test.rb"
217
+ ]
218
+
219
+ if s.respond_to? :specification_version then
220
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
221
+ s.specification_version = 2
222
+
223
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
224
+ else
225
+ end
226
+ else
227
+ end
228
+ end