the_role 2.1.1 → 2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +27 -3
  3. data/.ruby-gemset.example +1 -0
  4. data/.ruby-version.example +1 -0
  5. data/.rvmrc.example +1 -1
  6. data/.travis.yml +2 -2
  7. data/README.md +46 -47
  8. data/app/assets/javascripts/the_role_editinplace.js.coffee +32 -0
  9. data/app/controllers/admin/role_sections_controller.rb +2 -2
  10. data/app/controllers/admin/roles_controller.rb +2 -2
  11. data/app/controllers/concerns/controller.rb +23 -0
  12. data/{lib/generators/the_role/templates → app/models/_templates_}/role.rb +1 -1
  13. data/app/models/concerns/base.rb +37 -0
  14. data/app/models/concerns/role.rb +134 -0
  15. data/app/models/concerns/user.rb +57 -0
  16. data/app/views/admin/roles/_role.html.haml +90 -69
  17. data/app/views/admin/roles/_sidebar.html.haml +16 -9
  18. data/app/views/admin/roles/new.html.haml +11 -10
  19. data/config/locales/en.yml +1 -0
  20. data/config/locales/es.yml +28 -28
  21. data/config/locales/ru.yml +1 -1
  22. data/db/migrate/20111025025129_create_roles.rb +7 -1
  23. data/docs/2.1.1.png +0 -0
  24. data/lib/generators/the_role/USAGE +1 -1
  25. data/lib/generators/the_role/templates/the_role.rb +7 -2
  26. data/lib/generators/the_role/the_role_generator.rb +8 -5
  27. data/lib/tasks/roles.rake +1 -1
  28. data/lib/the_role/activerecord.rb +11 -0
  29. data/lib/the_role/config.rb +7 -0
  30. data/lib/the_role/version.rb +1 -1
  31. data/lib/the_role.rb +19 -5
  32. data/spec/dummy_app/.gitignore +18 -0
  33. data/spec/dummy_app/.rspec +1 -0
  34. data/spec/dummy_app/Gemfile +32 -0
  35. data/spec/dummy_app/README.md +39 -0
  36. data/spec/dummy_app/Rakefile +6 -0
  37. data/spec/dummy_app/app/assets/images/.keep +0 -0
  38. data/spec/dummy_app/app/assets/javascripts/application.js +17 -0
  39. data/spec/dummy_app/app/assets/stylesheets/app/style.css.scss +23 -0
  40. data/spec/dummy_app/app/assets/stylesheets/application.css +3 -0
  41. data/spec/dummy_app/app/controllers/application_controller.rb +38 -0
  42. data/spec/dummy_app/app/controllers/concerns/.keep +0 -0
  43. data/spec/dummy_app/app/controllers/pages_controller.rb +75 -0
  44. data/spec/dummy_app/app/controllers/users_controller.rb +32 -0
  45. data/spec/dummy_app/app/controllers/welcome_controller.rb +13 -0
  46. data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
  47. data/spec/dummy_app/app/mailers/.keep +0 -0
  48. data/spec/dummy_app/app/models/.keep +0 -0
  49. data/spec/dummy_app/app/models/concerns/.keep +0 -0
  50. data/spec/dummy_app/app/models/page.rb +24 -0
  51. data/spec/dummy_app/app/models/role.rb +4 -0
  52. data/spec/dummy_app/app/models/user.rb +21 -0
  53. data/spec/dummy_app/app/views/layouts/_current_user_info.html.haml +17 -0
  54. data/spec/dummy_app/app/views/layouts/application.html.haml +68 -0
  55. data/spec/dummy_app/app/views/pages/_form.html.haml +19 -0
  56. data/spec/dummy_app/app/views/pages/edit.html.haml +7 -0
  57. data/spec/dummy_app/app/views/pages/index.html.haml +27 -0
  58. data/spec/dummy_app/app/views/pages/manage.html.haml +23 -0
  59. data/spec/dummy_app/app/views/pages/my.html.haml +10 -0
  60. data/spec/dummy_app/app/views/pages/new.html.haml +5 -0
  61. data/spec/dummy_app/app/views/pages/show.html.haml +15 -0
  62. data/spec/dummy_app/app/views/users/edit.html.haml +34 -0
  63. data/spec/dummy_app/app/views/welcome/index.html.haml +38 -0
  64. data/spec/dummy_app/app/views/welcome/profile.html.haml +2 -0
  65. data/spec/dummy_app/bin/bundle +3 -0
  66. data/spec/dummy_app/bin/rails +4 -0
  67. data/spec/dummy_app/bin/rake +4 -0
  68. data/spec/dummy_app/config/application.rb +23 -0
  69. data/spec/dummy_app/config/boot.rb +4 -0
  70. data/spec/dummy_app/config/database.yml +17 -0
  71. data/spec/dummy_app/config/environment.rb +5 -0
  72. data/spec/dummy_app/config/environments/development.rb +29 -0
  73. data/spec/dummy_app/config/environments/production.rb +80 -0
  74. data/spec/dummy_app/config/environments/test.rb +36 -0
  75. data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
  76. data/spec/dummy_app/config/initializers/devise.rb +227 -0
  77. data/spec/dummy_app/config/initializers/filter_parameter_logging.rb +4 -0
  78. data/spec/dummy_app/config/initializers/inflections.rb +16 -0
  79. data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
  80. data/spec/dummy_app/config/initializers/secret_token.rb +12 -0
  81. data/spec/dummy_app/config/initializers/session_store.rb +3 -0
  82. data/spec/dummy_app/config/initializers/the_role.rb +6 -0
  83. data/spec/dummy_app/config/initializers/wrap_parameters.rb +14 -0
  84. data/spec/dummy_app/config/locales/devise.en.yml +57 -0
  85. data/spec/dummy_app/config/locales/en.yml +7 -0
  86. data/spec/dummy_app/config/locales/ru.yml +4 -0
  87. data/spec/dummy_app/config/routes.rb +20 -0
  88. data/spec/dummy_app/config.ru +4 -0
  89. data/spec/dummy_app/db/migrate/20120212061952_devise_create_users.rb +63 -0
  90. data/spec/dummy_app/db/migrate/20120212063249_create_roles.rb +18 -0
  91. data/spec/dummy_app/db/migrate/20120314061307_create_pages.rb +14 -0
  92. data/spec/dummy_app/db/schema.rb +59 -0
  93. data/spec/dummy_app/db/seeds.rb +85 -0
  94. data/spec/dummy_app/lib/assets/.keep +0 -0
  95. data/spec/dummy_app/lib/tasks/.keep +0 -0
  96. data/spec/dummy_app/lib/tasks/assets.rake +15 -0
  97. data/spec/dummy_app/lib/tasks/db_bootstrap.rake +16 -0
  98. data/spec/dummy_app/log/.keep +0 -0
  99. data/spec/dummy_app/public/404.html +58 -0
  100. data/spec/dummy_app/public/422.html +58 -0
  101. data/spec/dummy_app/public/500.html +57 -0
  102. data/spec/dummy_app/public/favicon.ico +0 -0
  103. data/spec/dummy_app/public/robots.txt +5 -0
  104. data/spec/dummy_app/spec/controllers/admin_roles_controller_spec.rb +52 -0
  105. data/spec/dummy_app/spec/controllers/pages_controller_spec.rb +141 -0
  106. data/spec/dummy_app/spec/controllers/welcome_controller_spec.rb +66 -0
  107. data/spec/dummy_app/spec/factories/page.rb +6 -0
  108. data/spec/dummy_app/spec/factories/role.rb +55 -0
  109. data/spec/dummy_app/spec/factories/user.rb +11 -0
  110. data/spec/dummy_app/spec/models/hash_spec.rb +272 -0
  111. data/spec/dummy_app/spec/models/param_process_spec.rb +44 -0
  112. data/spec/dummy_app/spec/models/role_spec.rb +218 -0
  113. data/spec/dummy_app/spec/models/user_spec.rb +164 -0
  114. data/spec/dummy_app/spec/routing/admin_roles_routing_spec.rb +41 -0
  115. data/spec/dummy_app/spec/routing/pages_routing_spec.rb +35 -0
  116. data/spec/dummy_app/spec/spec_helper.rb +68 -0
  117. data/spec/dummy_app/vendor/assets/javascripts/.keep +0 -0
  118. data/spec/dummy_app/vendor/assets/stylesheets/.keep +0 -0
  119. data/the_role.gemspec +2 -1
  120. data/the_role.yml.teamocil.example +11 -0
  121. metadata +213 -16
  122. data/app/assets/javascripts/the_role.js.coffee +0 -31
  123. data/app/assets/stylesheets/the_role/bootstrap_sass.css.scss +0 -20
  124. data/app/assets/stylesheets/the_role.css.scss +0 -47
  125. data/app/controllers/the_role_controller.rb +0 -18
  126. data/app/models/concerns/role_model.rb +0 -125
  127. data/app/models/concerns/the_role_base.rb +0 -35
  128. data/app/models/concerns/the_role_user_model.rb +0 -54
@@ -0,0 +1,59 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended that you check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(version: 20120314061307) do
15
+
16
+ create_table "pages", force: true do |t|
17
+ t.integer "user_id"
18
+ t.integer "person_id"
19
+ t.string "title"
20
+ t.text "content"
21
+ t.string "state", default: "draft"
22
+ t.datetime "created_at"
23
+ t.datetime "updated_at"
24
+ end
25
+
26
+ create_table "roles", force: true do |t|
27
+ t.string "name"
28
+ t.string "title"
29
+ t.text "description"
30
+ t.text "the_role"
31
+ t.datetime "created_at"
32
+ t.datetime "updated_at"
33
+ end
34
+
35
+ create_table "users", force: true do |t|
36
+ t.string "name"
37
+ t.string "company"
38
+ t.string "address"
39
+ t.string "some_protected_field", default: "should_not_be_changed"
40
+ t.string "email", default: "", null: false
41
+ t.string "encrypted_password", default: "", null: false
42
+ t.string "password", default: "", null: false
43
+ t.string "reset_password_token"
44
+ t.datetime "reset_password_sent_at"
45
+ t.integer "role_id"
46
+ t.datetime "remember_created_at"
47
+ t.integer "sign_in_count", default: 0
48
+ t.datetime "current_sign_in_at"
49
+ t.datetime "last_sign_in_at"
50
+ t.string "current_sign_in_ip"
51
+ t.string "last_sign_in_ip"
52
+ t.datetime "created_at"
53
+ t.datetime "updated_at"
54
+ end
55
+
56
+ add_index "users", ["email"], name: "index_users_on_email", unique: true
57
+ add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
58
+
59
+ end
@@ -0,0 +1,85 @@
1
+ ##############################
2
+ # Roles
3
+ ##############################
4
+ Role.create!(
5
+ name: :user,
6
+ title: :role_for_users,
7
+ description: :user_can_edit_his_pages,
8
+ the_role: {
9
+ pages: {
10
+ index: true,
11
+ show: true,
12
+ new: true,
13
+ create: true,
14
+ edit: true,
15
+ update: true,
16
+ destroy: true,
17
+ my: true,
18
+ secret: false
19
+ }
20
+ }
21
+ )
22
+
23
+ Role.create!(
24
+ name: :pages_moderator,
25
+ title: :pages_moderator,
26
+ description: :can_do_anything_with_pages,
27
+ the_role: { moderator: { pages: true } }
28
+ )
29
+
30
+ TheRole.create_admin_role!
31
+
32
+ p "Roles created"
33
+
34
+ ##############################
35
+ # Users
36
+ ##############################
37
+ User.create!(
38
+ email: 'admin@site.com',
39
+ name: Faker::Name.name,
40
+ company: Faker::Company.name,
41
+ address: Faker::Address.street_address,
42
+ password: 'qwerty',
43
+ password_confirmation: 'qwerty',
44
+ role: Role.with_name(:admin)
45
+ )
46
+
47
+ User.create!(
48
+ email: Faker::Internet.email,
49
+ name: Faker::Name.name,
50
+ company: Faker::Company.name,
51
+ address: Faker::Address.street_address,
52
+ password: 'qwerty',
53
+ password_confirmation: 'qwerty',
54
+ role: Role.with_name(:pages_moderator)
55
+ )
56
+
57
+ 5.times do
58
+ User.create!(
59
+ email: Faker::Internet.email,
60
+ name: Faker::Name.name,
61
+ company: Faker::Company.name,
62
+ address: Faker::Address.street_address,
63
+ password: 'qwerty',
64
+ password_confirmation: 'qwerty',
65
+ role: Role.with_name(:user)
66
+ )
67
+ end
68
+
69
+ p "Users created"
70
+
71
+ ##############################
72
+ # Pages
73
+ ##############################
74
+
75
+ User.all.each do |user|
76
+ 10.times do
77
+ user.pages.create!(
78
+ title: Faker::Lorem.sentence,
79
+ content: Faker::Lorem.paragraphs(3).join,
80
+ state: %w[draft published].sample
81
+ )
82
+ end
83
+ end
84
+
85
+ p "Pages created"
File without changes
File without changes
@@ -0,0 +1,15 @@
1
+ namespace :assets do
2
+ # rake assets:drop
3
+ desc "Drop assets"
4
+ task drop: :environment do
5
+ Rake::Task["assets:clean"].invoke
6
+ Rake::Task["assets:clobber"].invoke
7
+ end
8
+
9
+ # rake assets:build
10
+ desc "Precompile assets"
11
+ task build: :environment do
12
+ Rake::Task["assets:drop"].invoke
13
+ Rake::Task["assets:precompile"].invoke
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ namespace :db do
2
+ # rake db:bootstrap
3
+ desc "Reset DB"
4
+ task bootstrap: :environment do
5
+ Rake::Task["db:drop"].invoke
6
+ Rake::Task["db:create"].invoke
7
+ Rake::Task["db:migrate"].invoke
8
+ end
9
+
10
+ # rake db:bootstrap_and_seed
11
+ desc "Reset DB and seed"
12
+ task bootstrap_and_seed: :environment do
13
+ Rake::Task["db:bootstrap"].invoke
14
+ Rake::Task["db:seed"].invoke
15
+ end
16
+ end
File without changes
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-agent: *
5
+ # Disallow: /
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Admin::RolesController do
4
+ describe "Admin Section" do
5
+ describe 'Unauthorized' do
6
+ before(:each) do
7
+ @request.env['HTTP_REFERER'] = '/'
8
+ @role = FactoryGirl.create(:role_user)
9
+ end
10
+
11
+ %w{ index new }.each do |action|
12
+ it action.upcase do
13
+ get action
14
+ response.should redirect_to new_user_session_path
15
+ end
16
+ end
17
+
18
+ %w{ edit update create destroy }.each do |action|
19
+ it action.upcase do
20
+ get action, { id: @role.id }
21
+ response.should redirect_to new_user_session_path
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "Authorized / Regular user" do
27
+ describe "Can't do something with Roles" do
28
+ before(:each) do
29
+ @request.env['HTTP_REFERER'] = '/'
30
+ @user = FactoryGirl.create(:user)
31
+ @role = FactoryGirl.create(:role_user)
32
+ sign_in @user
33
+ end
34
+
35
+ %w{ index new }.each do |action|
36
+ it action.upcase do
37
+ get action
38
+ response.body.should match access_denied_match
39
+ end
40
+ end
41
+
42
+ %w{ edit update create destroy }.each do |action|
43
+ it action.upcase do
44
+ get action, { id: @role.id }
45
+ response.body.should match access_denied_match
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,141 @@
1
+ require 'spec_helper'
2
+
3
+ describe PagesController do
4
+ def valid_page_attrs
5
+ {
6
+ title: Faker::Lorem.sentence,
7
+ content: Faker::Lorem.sentence,
8
+ state: :published
9
+ }
10
+ end
11
+
12
+ def valid_page_for user
13
+ valid_page_attrs.merge(user_id: user.id)
14
+ end
15
+
16
+ before(:each) do
17
+ @role = FactoryGirl.create(:role_user)
18
+ @moderator_role = FactoryGirl.create(:role_moderator)
19
+
20
+ @owner = FactoryGirl.create(:user, role: @role)
21
+ @hacker = FactoryGirl.create(:user, role: @role)
22
+ @moderator = FactoryGirl.create(:user, role: @moderator_role)
23
+
24
+ @owner.pages.create! valid_page_for(@owner)
25
+ end
26
+
27
+ describe "Guest" do
28
+ describe 'NOT AUTORIZED/NO ROLE/NOT OWNER' do
29
+ it "CREATE / but should be redirected" do
30
+ post :create, { page: { fake: true } }
31
+ response.should redirect_to new_user_session_path
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "User" do
37
+ describe 'AUTORIZED/HAS ROLE/OWNER' do
38
+ before(:each) { sign_in @owner }
39
+
40
+ context "CREATE" do
41
+ it "valid" do
42
+ expect {
43
+ post :create , { page: valid_page_for(@owner) }
44
+ }.to change(Page, :count).by(1)
45
+ end
46
+
47
+ it "invalid params" do
48
+ expect {
49
+ post :create, { page: { fake: true } }
50
+ }.to_not change(Page, :count)
51
+
52
+ response.should render_template :new
53
+ end
54
+
55
+ it "valid, no errors" do
56
+ post :create , { page: valid_page_for(@owner) }
57
+ assigns(:page).errors.should be_empty
58
+ end
59
+
60
+ it "valid, redirect to SHOW" do
61
+ post :create, { page: valid_page_for(@owner) }
62
+ response.should redirect_to page_path assigns(:page)
63
+ end
64
+ end
65
+
66
+ context "UPDATE" do
67
+ before(:each) do
68
+ sign_in @owner
69
+ @page = @owner.pages.last
70
+ end
71
+
72
+ it "users should has rules" do
73
+ @owner.has_role?(:pages, :update).should be_true
74
+ @hacker.has_role?(:pages, :update).should be_true
75
+ end
76
+
77
+ it "page should be updated" do
78
+ old_title = @page.title
79
+ new_title = "test_title"
80
+
81
+ expect {
82
+ patch :update, id: @page, page: { title: new_title }
83
+ @page.reload
84
+ }.to change(@page, :title).from(old_title).to(new_title)
85
+ end
86
+ end
87
+ end
88
+
89
+ describe 'AUTORIZED/HAS ROLE/NOT OWNER' do
90
+ before(:each) { @page = @owner.pages.last }
91
+
92
+ it "hacker should be blocked" do
93
+ sign_in @hacker
94
+ @request.env['HTTP_REFERER'] = '/'
95
+ patch :update, id: @page, page: { title: "test_title" }
96
+ response.body.should match access_denied_match
97
+ end
98
+ end
99
+ end
100
+
101
+ describe "Moderator" do
102
+ before(:each) do
103
+ @page = @owner.pages.last
104
+
105
+ @old_title = @page.title
106
+ @new_title = Faker::Lorem.sentence
107
+ end
108
+
109
+ it "Owner can update page" do
110
+ sign_in @owner
111
+
112
+ expect {
113
+ patch :update, id: @page, page: { title: @new_title }
114
+ @page.reload
115
+ }.to change(@page, :title).from(@old_title).to(@new_title)
116
+ end
117
+
118
+ it "Moderator can update page" do
119
+ sign_in @moderator
120
+
121
+ expect {
122
+ patch :update, id: @page, page: { title: @new_title }
123
+ @page.reload
124
+ }.to change(@page, :title).from(@old_title).to(@new_title)
125
+ end
126
+
127
+ it "Hacker cant update page" do
128
+ sign_in @hacker
129
+ @request.env['HTTP_REFERER'] = '/'
130
+
131
+ expect {
132
+ patch :update, id: @page, page: { title: @new_title }
133
+ @page.reload
134
+ }.to_not change(@page, :title).from(@old_title).to(@new_title)
135
+ end
136
+ end
137
+ end
138
+
139
+ # assigns(:page).should eq @page
140
+ # response.should render_template :manage
141
+ # response.should redirect_to new_user_session_path
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe WelcomeController do
4
+ describe "GET for GUESTS" do
5
+ it "*INDEX* test *subject* object" do
6
+ get 'index'
7
+ subject.class.should == WelcomeController
8
+ end
9
+
10
+ it "*INDEX* returns http success" do
11
+ get 'index'
12
+ response.should be_success
13
+ end
14
+
15
+ it "*INDEX* render :index page" do
16
+ get 'index'
17
+ response.should render_template :index
18
+ end
19
+
20
+ it "*INDEX* *current_user* should be nil" do
21
+ get 'index'
22
+ subject.current_user.should be_nil
23
+ end
24
+
25
+ it "*PROFILE* will be redirect" do
26
+ get 'profile'
27
+ response.should be_redirect
28
+ end
29
+
30
+ it "*PROFILE* will be redirect to new_user_session_path page" do
31
+ get 'profile'
32
+ response.should redirect_to new_user_session_path
33
+ end
34
+ end
35
+
36
+ describe "GET for LOGGED_IN users" do
37
+ before(:each) do
38
+ @user = FactoryGirl.create(:user)
39
+ sign_in @user
40
+ end
41
+
42
+ after(:each) do
43
+ User.destroy_all
44
+ end
45
+
46
+ it "One user should be exists" do
47
+ User.count.should be 1
48
+ end
49
+
50
+ it "*PROFILE* should render :profile page" do
51
+ get 'profile'
52
+ response.should render_template :profile
53
+ end
54
+
55
+ it "*PROFILE* should not to be redirect" do
56
+ get 'profile'
57
+ response.should_not be_redirect
58
+ end
59
+
60
+ it "*PROFILE* *current_user* helper should return user" do
61
+ get 'profile'
62
+ subject.current_user.should == @user
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ factory :page, class: Page do
3
+ sequence(:title) { Faker::Lorem.sentence }
4
+ sequence(:content) { Faker::Lorem.paragraphs(3).join }
5
+ end
6
+ end
@@ -0,0 +1,55 @@
1
+ #############################################
2
+ # EMPTY role
3
+ #############################################
4
+ FactoryGirl.define do
5
+ factory :role_without_rules, class: Role do
6
+ name 'user'
7
+ title 'User role'
8
+ description 'Default Role for users'
9
+ end
10
+ end
11
+
12
+ #############################################
13
+ # USER role
14
+ #############################################
15
+ role_user = {
16
+ pages: {
17
+ index: true,
18
+ show: true,
19
+ new: true,
20
+ create: true,
21
+ edit: true,
22
+ update: true,
23
+ destroy: true,
24
+ my: true,
25
+ secret: false
26
+ }
27
+ }
28
+
29
+ FactoryGirl.define do
30
+ factory :role_user, class: Role do
31
+ name 'user'
32
+ title 'User role'
33
+ description 'Default Role for users'
34
+ the_role role_user
35
+ end
36
+ end
37
+
38
+ #############################################
39
+ # MODERATOR role
40
+ #############################################
41
+
42
+ role_moderator = {
43
+ moderator: {
44
+ pages: true
45
+ }
46
+ }
47
+
48
+ FactoryGirl.define do
49
+ factory :role_moderator, class: Role do
50
+ name 'pages_moderator'
51
+ title 'Pages moderator'
52
+ description 'Can do anything with pages'
53
+ the_role role_moderator
54
+ end
55
+ end