challah 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. data/CHANGELOG.md +9 -2
  2. data/README.md +18 -18
  3. data/lib/challah/test.rb +22 -5
  4. data/lib/challah/version.rb +1 -1
  5. data/test/audit_test.rb +32 -32
  6. data/test/controller_test.rb +9 -9
  7. data/test/cookie_store_test.rb +25 -25
  8. data/test/factories.rb +7 -7
  9. data/test/helper.rb +14 -12
  10. data/test/permission_test.rb +14 -14
  11. data/test/restrictions_controller_test.rb +29 -30
  12. data/test/role_test.rb +26 -26
  13. data/test/session_test.rb +65 -65
  14. data/test/sessions_controller_test.rb +13 -13
  15. data/test/simple_cookie_store_test.rb +25 -25
  16. data/test/user_test.rb +79 -79
  17. data/vendor/bundle/cache/factory_girl-3.0.0.gem +0 -0
  18. data/vendor/bundle/gems/factory_girl-3.0.0/Appraisals +11 -0
  19. data/vendor/bundle/gems/factory_girl-3.0.0/CONTRIBUTION_GUIDELINES.md +10 -0
  20. data/vendor/bundle/gems/factory_girl-3.0.0/Changelog +168 -0
  21. data/vendor/bundle/gems/factory_girl-3.0.0/GETTING_STARTED.md +735 -0
  22. data/vendor/bundle/gems/factory_girl-3.0.0/Gemfile +5 -0
  23. data/vendor/bundle/gems/factory_girl-3.0.0/Gemfile.lock +95 -0
  24. data/vendor/bundle/gems/factory_girl-3.0.0/LICENSE +19 -0
  25. data/vendor/bundle/gems/factory_girl-3.0.0/README.md +70 -0
  26. data/vendor/bundle/gems/factory_girl-3.0.0/Rakefile +38 -0
  27. data/vendor/bundle/gems/factory_girl-3.0.0/cucumber.yml +1 -0
  28. data/vendor/bundle/gems/factory_girl-3.0.0/factory_girl.gemspec +38 -0
  29. data/vendor/bundle/gems/factory_girl-3.0.0/features/factory_girl_steps.feature +237 -0
  30. data/vendor/bundle/gems/factory_girl-3.0.0/features/find_definitions.feature +75 -0
  31. data/vendor/bundle/gems/factory_girl-3.0.0/features/step_definitions/database_steps.rb +42 -0
  32. data/vendor/bundle/gems/factory_girl-3.0.0/features/step_definitions/factory_girl_steps.rb +43 -0
  33. data/vendor/bundle/gems/factory_girl-3.0.0/features/support/env.rb +11 -0
  34. data/vendor/bundle/gems/factory_girl-3.0.0/features/support/factories.rb +119 -0
  35. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/2.3.gemfile +7 -0
  36. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.0.gemfile +7 -0
  37. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.0.gemfile.lock +86 -0
  38. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.1.gemfile +7 -0
  39. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.1.gemfile.lock +95 -0
  40. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.2.gemfile +7 -0
  41. data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.2.gemfile.lock +93 -0
  42. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl.rb +69 -0
  43. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/aliases.rb +19 -0
  44. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute.rb +40 -0
  45. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/association.rb +23 -0
  46. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/dynamic.rb +20 -0
  47. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/sequence.rb +17 -0
  48. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/static.rb +15 -0
  49. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute_assigner.rb +73 -0
  50. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute_list.rb +54 -0
  51. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/callback.rb +33 -0
  52. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration.rb +22 -0
  53. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/association.rb +25 -0
  54. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/dynamic.rb +25 -0
  55. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/implicit.rb +32 -0
  56. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/static.rb +25 -0
  57. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration_list.rb +48 -0
  58. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/definition.rb +76 -0
  59. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/definition_proxy.rb +159 -0
  60. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/errors.rb +19 -0
  61. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/evaluator.rb +76 -0
  62. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/evaluator_class_definer.rb +34 -0
  63. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/factory.rb +145 -0
  64. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/factory_runner.rb +24 -0
  65. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/find_definitions.rb +25 -0
  66. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/null_factory.rb +15 -0
  67. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/null_object.rb +7 -0
  68. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/registry.rb +46 -0
  69. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/reload.rb +8 -0
  70. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/sequence.rb +24 -0
  71. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/step_definitions.rb +130 -0
  72. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy.rb +32 -0
  73. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/attributes_for.rb +12 -0
  74. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/build.rb +15 -0
  75. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/create.rb +17 -0
  76. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/stub.rb +61 -0
  77. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy_calculator.rb +29 -0
  78. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax.rb +16 -0
  79. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/blueprint.rb +42 -0
  80. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/default.rb +56 -0
  81. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/generate.rb +70 -0
  82. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb +45 -0
  83. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/methods.rb +136 -0
  84. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/sham.rb +45 -0
  85. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/vintage.rb +130 -0
  86. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/trait.rb +29 -0
  87. data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/version.rb +4 -0
  88. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/aliases_spec.rb +19 -0
  89. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attribute_aliases_spec.rb +45 -0
  90. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attribute_existing_on_object_spec.rb +68 -0
  91. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_for_spec.rb +89 -0
  92. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_from_instance_spec.rb +53 -0
  93. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_ordered_spec.rb +51 -0
  94. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_list_spec.rb +41 -0
  95. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_spec.rb +89 -0
  96. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_stubbed_spec.rb +104 -0
  97. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/callbacks_spec.rb +47 -0
  98. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/create_list_spec.rb +82 -0
  99. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/create_spec.rb +117 -0
  100. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/define_child_before_parent_spec.rb +21 -0
  101. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/definition_spec.rb +26 -0
  102. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/definition_without_block_spec.rb +15 -0
  103. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/initialize_with_spec.rb +147 -0
  104. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_factories_spec.rb +184 -0
  105. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_inherited_spec.rb +52 -0
  106. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/nested_attributes_spec.rb +32 -0
  107. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/overrides_spec.rb +61 -0
  108. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/parent_spec.rb +90 -0
  109. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/sequence_spec.rb +33 -0
  110. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/stub_spec.rb +62 -0
  111. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/blueprint_spec.rb +34 -0
  112. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/generate_spec.rb +59 -0
  113. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/make_spec.rb +52 -0
  114. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/sham_spec.rb +43 -0
  115. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/vintage_spec.rb +217 -0
  116. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/traits_spec.rb +421 -0
  117. data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/transient_attributes_spec.rb +124 -0
  118. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/aliases_spec.rb +31 -0
  119. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/association_spec.rb +28 -0
  120. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/dynamic_spec.rb +52 -0
  121. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/sequence_spec.rb +16 -0
  122. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/static_spec.rb +19 -0
  123. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute_list_spec.rb +78 -0
  124. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute_spec.rb +16 -0
  125. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/callback_spec.rb +41 -0
  126. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/declaration/implicit_spec.rb +25 -0
  127. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/declaration_list_spec.rb +71 -0
  128. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/definition_proxy_spec.rb +197 -0
  129. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/definition_spec.rb +104 -0
  130. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/evaluator_class_definer_spec.rb +54 -0
  131. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/factory_spec.rb +279 -0
  132. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/find_definitions_spec.rb +110 -0
  133. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/null_factory_spec.rb +13 -0
  134. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/null_object_spec.rb +8 -0
  135. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/registry_spec.rb +81 -0
  136. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/sequence_spec.rb +47 -0
  137. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/attributes_for_spec.rb +18 -0
  138. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/build_spec.rb +7 -0
  139. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/create_spec.rb +13 -0
  140. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/stub_spec.rb +40 -0
  141. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy_calculator_spec.rb +33 -0
  142. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy_spec.rb +21 -0
  143. data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl_spec.rb +22 -0
  144. data/vendor/bundle/gems/factory_girl-3.0.0/spec/spec_helper.rb +26 -0
  145. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/macros/define_constant.rb +86 -0
  146. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/callback.rb +9 -0
  147. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/declaration.rb +71 -0
  148. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb +44 -0
  149. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/trait.rb +9 -0
  150. data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/shared_examples/strategy.rb +104 -0
  151. data/vendor/bundle/specifications/factory_girl-3.0.0.gemspec +62 -0
  152. metadata +147 -12
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## Challah 0.5.3
2
+
3
+ * Updated tests to conform with Factory Girl 3.0
4
+ * Added `login_as` and `logout` test helper methods into `ActiveSupport::TestCase` by default. These methods can be used within functional tests to authenticate a user for a given test.
5
+ * For each test run, all test sessions are cleared.
6
+ * Removing support for Ruby 1.8.7, since Factory Girl does not support it anymore.
7
+
1
8
  ## Challah 0.5.2
2
9
 
3
10
  * Created `SimpleCookieStore` and use it as the default storage method for Session. This varies from `CookieStore` only because the user agent and remote IP address are not used in the cookie.
@@ -41,12 +48,12 @@
41
48
 
42
49
  ## Challah 0.3.1
43
50
 
44
- * Removed name spacing of controllers and default routes.
51
+ * Removed name spacing of controllers and default routes.
45
52
  * Added option to not include default routes
46
53
 
47
54
  ## Challah 0.3.0
48
55
 
49
- * Documentation clean up.
56
+ * Documentation clean up.
50
57
  * Added rake tasks for creating role, permission and user records.
51
58
 
52
59
  ## Challah 0.2.0
data/README.md CHANGED
@@ -8,7 +8,7 @@ Challah doesn't provide any fancy controllers or views that clutter your app or
8
8
 
9
9
  ## Requirements
10
10
 
11
- * Ruby 1.8.7, 1.9.2 or 1.9.3
11
+ * Ruby 1.9.2+
12
12
  * Bundler
13
13
  * Rails 3.1+
14
14
 
@@ -25,8 +25,8 @@ Or, in your `Gemfile`
25
25
  Once the gem has been set up and installed, run the following command to set up the database migrations:
26
26
 
27
27
  rake challah:setup
28
-
29
- This will copy over the necessary migrations to your app, migrate the database and add some seed data. You will be prompted to add the first user as the last step in this process.
28
+
29
+ This will copy over the necessary migrations to your app, migrate the database and add some seed data. You will be prompted to add the first user as the last step in this process.
30
30
 
31
31
  ### Manual set up
32
32
 
@@ -36,7 +36,7 @@ If you would prefer to handle these steps manually, you can do so by using these
36
36
  rake db:migrate
37
37
  rake challah:setup:seeds
38
38
  rake challah:users:create
39
-
39
+
40
40
  ### Creating users, permissions and roles
41
41
 
42
42
  Since Challah doesn't provide any controller and views for users, permissions and roles there are a few handy rake tasks you can use to create new records.
@@ -46,10 +46,10 @@ The following tasks will prompt for the various attributes in each model:
46
46
  rake challah:permissions:create # => Create a new Permission record
47
47
  rake challah:roles:create # => Create a new Role record
48
48
  rake challah:users:create # => Creates a new User record
49
-
49
+
50
50
  ## Models
51
51
 
52
- Challah provides three core models to your app: Permission, Role and User. By default, these models are hidden away in the Challah gem engine, but you can always copy the models into your app to make further modifications to the functionality.
52
+ Challah provides three core models to your app: Permission, Role and User. By default, these models are hidden away in the Challah gem engine, but you can always copy the models into your app to make further modifications to the functionality.
53
53
 
54
54
  ### User
55
55
 
@@ -71,9 +71,9 @@ The default Challah installation creates two permissions by default: `admin` and
71
71
 
72
72
  ### Role
73
73
 
74
- A role is used to group together various permissions and assign them to a user. Roles can also be thought of as user groups. Each role record requires a unique name.
74
+ A role is used to group together various permissions and assign them to a user. Roles can also be thought of as user groups. Each role record requires a unique name.
75
75
 
76
- Roles should only be used within your app to consolidate various permissions into logical groups. Roles are not intended to be used to restrict functionality, use permissions instead.
76
+ Roles should only be used within your app to consolidate various permissions into logical groups. Roles are not intended to be used to restrict functionality, use permissions instead.
77
77
 
78
78
  The default Challah installation creates two roles by default: 'Administrator' and 'Default'. Administrators have all permissions, now and in the future. Default users have no permissions other than being able to log in.
79
79
 
@@ -103,12 +103,12 @@ For example, restrict the second list item to only users that have logged in:
103
103
  <li><a href="/public-stuff">Not-so-secret Stuff</a></li>
104
104
  </ul>
105
105
 
106
- Controllers can also be restricted using `before_filter`:
106
+ Controllers can also be restricted using `before_filter`:
107
107
 
108
108
  class WidgetsController < ApplicationController
109
109
  before_filter :login_required
110
110
 
111
- # …
111
+ # …
112
112
  end
113
113
 
114
114
  Or, you can call `restrict_to_authenticated` instead, which does the same thing:
@@ -116,7 +116,7 @@ Or, you can call `restrict_to_authenticated` instead, which does the same thing:
116
116
  class WidgetsController < ApplicationController
117
117
  restrict_to_authenticated
118
118
 
119
- # ...
119
+ # ...
120
120
  end
121
121
 
122
122
  All normal Rails `before_filter` options apply, so you can always limit this restriction to a specific action:
@@ -124,12 +124,12 @@ All normal Rails `before_filter` options apply, so you can always limit this res
124
124
  class WidgetsController < ApplicationController
125
125
  restrict_to_authenticated :only => [ :edit, :update, :destroy ]
126
126
 
127
- # ...
127
+ # ...
128
128
  end
129
129
 
130
130
  ### Checking for a permission
131
131
 
132
- Since Challah is a permissions-based system, all restricted access should be performed by testing a user for the given permission.
132
+ Since Challah is a permissions-based system, all restricted access should be performed by testing a user for the given permission.
133
133
 
134
134
  Anywhere you can access a user instance, you can use the `has` method and pass in a single permission key to test that user for access:
135
135
 
@@ -143,7 +143,7 @@ Anywhere you can access a user instance, you can use the `has` method and pass i
143
143
  <li><a href="/public-stuff">Not-so-secret Stuff</a></li>
144
144
  </ul>
145
145
 
146
- Notice that we checked for existance of the user before we checked to see if the user has a permission. If you used the `restrict_to_authenticated` method in your controller, you can likely skip this step.
146
+ Notice that we checked for existance of the user before we checked to see if the user has a permission. If you used the `restrict_to_authenticated` method in your controller, you can likely skip this step.
147
147
 
148
148
  Note: `current_user` will return `nil` if there is no user available, so checking for `current_user?` prevents you from calling `has` on `nil`.
149
149
 
@@ -152,7 +152,7 @@ For controller restrictions, use the `restrict_to_permission` method:
152
152
  class WidgetsController < ApplicationController
153
153
  restrict_to_permission :manage_widgets
154
154
 
155
- # ...
155
+ # ...
156
156
  end
157
157
 
158
158
  The `restrict_to_permission` method will also fail if there is no user currently authenticated.
@@ -162,7 +162,7 @@ And, just as before, we can use the Rails filter options to limit the restrictio
162
162
  class WidgetsController < ApplicationController
163
163
  restrict_to_permission :admin, :only => [ :destroy ]
164
164
 
165
- # ...
165
+ # ...
166
166
  end
167
167
 
168
168
  And of course, you can stack up multiple restrictions get very specific about what your users can do:
@@ -176,7 +176,7 @@ And of course, you can stack up multiple restrictions get very specific about wh
176
176
  restrict_to_permission :manage_widgets, :except => [ :index, :destroy ]
177
177
  restrict_to_permission :admin, :only => [ :destroy ]
178
178
 
179
- # ...
179
+ # ...
180
180
  end
181
181
 
182
182
  Whichever method you use will yield the same results. Just make sure you are checking for a permission key, and not checking for a role. Checking for roles (i.e.: `user.role_id == 1`) is shameful practice. Use permissions!
@@ -188,7 +188,7 @@ By default, there are a few routes included with the Challah engine. These route
188
188
  GET /login # => SessionsController#new
189
189
  POST /login # => SessionsController#create
190
190
  GET /logout # => SessionsController#new
191
-
191
+
192
192
  Feel free to override the `SessionsController` with something more appropriate for your app.
193
193
 
194
194
  If you'd prefer to set up your own login/logout actions, you can skip the inclusion of the default routes by adding the following line to an initializer file in your app:
data/lib/challah/test.rb CHANGED
@@ -4,23 +4,40 @@ class TestSessionStore
4
4
  def initialize(session = nil)
5
5
  @session = session
6
6
  end
7
-
7
+
8
8
  def destroy
9
9
  $challah_test_session = nil
10
10
  end
11
-
11
+
12
12
  def read
13
13
  if $challah_test_session
14
14
  return $challah_test_session.to_s.split(':')
15
15
  end
16
-
16
+
17
17
  nil
18
18
  end
19
-
19
+
20
20
  def save(token, user_id)
21
21
  $challah_test_session = "#{token}:#{user_id}"
22
22
  true
23
23
  end
24
24
  end
25
25
 
26
- Challah.options[:storage_class] = TestSessionStore
26
+ Challah.options[:storage_class] = TestSessionStore
27
+
28
+ class ActiveSupport::TestCase
29
+ # Log the given user instance in
30
+ def login_as(user)
31
+ Challah::Session.create!(user)
32
+ end
33
+
34
+ # Log the given user instance out
35
+ def logout
36
+ Challah::Session.destroy
37
+ end
38
+
39
+ setup do
40
+ # Reset any challah user sessions for each test.
41
+ $challah_test_session = nil
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module Challah
2
- VERSION = "0.5.2" unless defined?(::Challah::VERSION)
2
+ VERSION = "0.5.3" unless defined?(::Challah::VERSION)
3
3
  end
data/test/audit_test.rb CHANGED
@@ -4,104 +4,104 @@ class AuditTest < ActiveSupport::TestCase
4
4
  include ActiveModel::Lint::Tests
5
5
 
6
6
  # Use Widget as a fake model to test auditing.
7
- class Widget
7
+ class Widget
8
8
  include ActiveModel::Conversion
9
9
  include ActiveModel::Validations
10
10
  extend ActiveModel::Naming
11
11
  extend ActiveModel::Callbacks
12
-
12
+
13
13
  define_model_callbacks :create, :update, :save
14
-
14
+
15
15
  include Challah::Audit
16
16
 
17
17
  attr_accessor :name, :created_by, :created_at, :updated_by, :updated_at
18
-
18
+
19
19
  def initialize(attributes = {})
20
20
  attributes.each do |name, value|
21
21
  send("#{name}=", value)
22
22
  end
23
-
23
+
24
24
  @attributes = {}
25
25
  end
26
-
26
+
27
27
  def persisted?
28
28
  false
29
29
  end
30
-
30
+
31
31
  def new_record?
32
32
  !@saved
33
33
  end
34
-
34
+
35
35
  def save
36
36
  # Saving doesn't do anything, just a stub
37
37
  run_callbacks :save do
38
38
  @saved = true
39
39
  end
40
-
40
+
41
41
  true
42
42
  end
43
-
43
+
44
44
  def column_for_attribute(attr_name)
45
45
  self.respond_to?("#{attr_name}=") ? attr_name : nil
46
46
  end
47
-
47
+
48
48
  def write_attribute(attr_name, value)
49
49
  self.send("#{attr_name}=", value)
50
50
  end
51
-
51
+
52
52
  # Stub for tests
53
53
  def changed_attributes
54
54
  {}
55
55
  end
56
-
56
+
57
57
  # Stubs
58
58
  def attribute_changed?(attr_name)
59
59
  false
60
60
  end
61
61
  end
62
-
63
- # Runs the ActiveModel::Lint tests against a new Widget instance.
62
+
63
+ # Runs the ActiveModel::Lint tests against a new Widget instance.
64
64
  def setup
65
65
  @model = Widget.new
66
66
  end
67
-
67
+
68
68
  context "An audited model" do
69
69
  should "be able to receive a current user" do
70
- user = Factory(:normal_user)
71
- user_two = Factory(:user, :first_name => 'User', :last_name => 'Test 2')
72
-
73
- assert_equal 0, @model.current_user_id
70
+ user = create(:normal_user)
71
+ user_two = create(:user, :first_name => 'User', :last_name => 'Test 2')
72
+
73
+ assert_equal 0, @model.current_user_id
74
74
  assert_equal true, @model.new_record?
75
-
75
+
76
76
  # For a new record, setting current_user should update both attributes
77
- @model.current_user = user
77
+ @model.current_user = user
78
78
  assert_equal user.id, @model.current_user_id
79
-
79
+
80
80
  @model.save
81
-
81
+
82
82
  assert_equal user.id, @model.created_by
83
83
  assert_equal user.id, @model.updated_by
84
-
84
+
85
85
  assert_equal false, @model.new_record?
86
-
86
+
87
87
  # For an existing record, setting current_user (or current_user_id) should update only updated_by
88
88
  @model.current_user_id = user_two.id
89
89
  assert_equal user_two.id, @model.current_user_id
90
-
90
+
91
91
  @model.save
92
-
92
+
93
93
  assert_equal user.id, @model.created_by
94
94
  assert_equal user_two.id, @model.updated_by
95
95
  end
96
-
96
+
97
97
  should "be able to clear audit attributes" do
98
98
  @model.created_by = 1
99
99
  @model.updated_by = 2
100
-
100
+
101
101
  @model.initialize_dup(nil)
102
-
102
+
103
103
  assert_equal nil, @model.created_by
104
104
  assert_equal nil, @model.updated_by
105
- end
105
+ end
106
106
  end
107
107
  end
@@ -2,31 +2,31 @@ require 'helper'
2
2
 
3
3
  class ControllerTest < ActiveSupport::TestCase
4
4
  include Challah
5
-
5
+
6
6
  context "A controller" do
7
7
  setup do
8
- @user = Factory(:user)
8
+ @user = create(:user)
9
9
  @controller = MockController.new
10
10
  end
11
-
11
+
12
12
  should "be logged out by default" do
13
13
  assert_equal false, @controller.send(:current_user?)
14
14
  end
15
-
16
- should "have logged_in? and current_user methods" do
15
+
16
+ should "have logged_in? and current_user methods" do
17
17
  session = Session.create(@user)
18
- session.save
19
-
18
+ session.save
19
+
20
20
  assert_equal true, @controller.send(:current_user?)
21
21
  assert_equal @user, @controller.send(:current_user)
22
22
  end
23
-
23
+
24
24
  should "redirect to login page if user is not logged in" do
25
25
  @controller.request.url = 'http://example.com/protected-page'
26
26
  @controller.stubs(:logged_in?).returns(false)
27
27
  @controller.expects(:redirect_to)
28
28
  @controller.send(:login_required)
29
-
29
+
30
30
  assert_equal @controller.session[:return_to], 'http://example.com/protected-page'
31
31
  end
32
32
  end
@@ -2,93 +2,93 @@ require 'helper'
2
2
 
3
3
  class CookieStoreTest < ActiveSupport::TestCase
4
4
  include Challah
5
-
5
+
6
6
  context "The CookieStore class" do
7
7
  setup do
8
- @user = Factory(:user)
8
+ @user = create(:user)
9
9
  @request = MockRequest.new
10
10
  end
11
-
11
+
12
12
  should "save session in a request cookie store" do
13
13
  assert_equal [], @request.cookies.keys
14
-
14
+
15
15
  session = Session.new(@request)
16
16
  session.store = CookieStore.new(session)
17
17
  session.persist = true
18
18
  session.user = @user
19
19
  session.save
20
-
20
+
21
21
  assert_equal %w( challah-s challah-v ), @request.cookies.keys.sort
22
22
  assert_equal "#{@user.persistence_token}@#{@user.id}", @request.cookies['challah-s'][:value]
23
23
  assert_equal "test.dev", @request.cookies['challah-s'][:domain]
24
-
24
+
25
25
  assert_equal Encrypter.md5("#{@user.persistence_token}@#{@user.id}", @request.user_agent, @request.remote_ip), @request.cookies['challah-v'][:value]
26
26
  assert_equal "test.dev", @request.cookies['challah-v'][:domain]
27
27
  end
28
-
28
+
29
29
  should "be able to inspect the store" do
30
30
  session = Session.new(@request)
31
31
  session.store = CookieStore.new(session)
32
32
  session.persist = true
33
33
  session.user = @user
34
34
  session.save
35
-
35
+
36
36
  assert session.store.inspect =~ /<CookieStore:(.*?)>/, 'Does not match'
37
- end
38
-
37
+ end
38
+
39
39
  should "read cookies and detect tampered verification cookies" do
40
40
  assert_equal [], @request.cookies.keys
41
-
41
+
42
42
  session = Session.new(@request)
43
43
  session.store = CookieStore.new(session)
44
44
  session.persist = true
45
45
  session.user = @user
46
46
  session.save
47
-
47
+
48
48
  validation_cookie_val = Encrypter.md5("#{@user.persistence_token}@#{@user.id}", @request.user_agent, @request.remote_ip)
49
49
  session_cookie_val = "#{@user.persistence_token}@#{@user.id}"
50
-
50
+
51
51
  assert_equal session_cookie_val, @request.cookies['challah-s'][:value]
52
52
  assert_equal session_cookie_val, session.store.send(:session_cookie)[:value]
53
53
  assert_equal validation_cookie_val, @request.cookies['challah-v'][:value]
54
54
  assert_equal validation_cookie_val, session.store.send(:validation_cookie)[:value]
55
-
55
+
56
56
  session.store.stubs(:validation_cookie).returns(validation_cookie_val)
57
57
  session.store.stubs(:session_cookie).returns(session_cookie_val)
58
-
58
+
59
59
  session2 = Session.new(@request)
60
60
  session2.persist = true
61
- session2.store = session.store
61
+ session2.store = session.store
62
62
  session2.read
63
-
63
+
64
64
  assert_equal true, session2.store.send(:existing?)
65
65
  assert_equal true, session2.valid?
66
66
  assert_equal @user.id, session2.user_id
67
-
67
+
68
68
  session.store.stubs(:validation_cookie).returns('bad-value')
69
-
69
+
70
70
  session3 = Session.new(@request)
71
71
  session3.store = session.store
72
72
  session3.read
73
-
73
+
74
74
  assert_equal false, session3.store.send(:existing?)
75
75
  assert_equal false, session3.valid?
76
76
  end
77
-
77
+
78
78
  should "delete sessions from cookies" do
79
79
  session = Session.new(@request)
80
80
  session.store = CookieStore.new(session)
81
81
  session.user = @user
82
82
  session.persist = true
83
-
83
+
84
84
  session.save
85
-
85
+
86
86
  assert_equal true, session.valid?
87
87
  assert_equal @user, session.user
88
88
  assert_equal %w( challah-s challah-v ), @request.cookies.keys.sort
89
-
89
+
90
90
  session.destroy
91
-
91
+
92
92
  assert_equal false, session.valid?
93
93
  assert_equal nil, session.user
94
94
  assert_equal [], @request.cookies.keys.sort