private_person 0.1.0

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 (60) hide show
  1. checksums.yaml +15 -0
  2. data/.document +5 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +21 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +18 -0
  7. data/Rakefile +49 -0
  8. data/VERSION +1 -0
  9. data/lib/generators/private_person/install/install_generator.rb +31 -0
  10. data/lib/generators/private_person/install/templates/migrate/create_permissions_table.rb +18 -0
  11. data/lib/generators/private_person/utils.rb +16 -0
  12. data/lib/private_person/models/permissible.rb +16 -0
  13. data/lib/private_person/models/permission.rb +58 -0
  14. data/lib/private_person/models/permissor.rb +17 -0
  15. data/lib/private_person/models/permitted.rb +44 -0
  16. data/lib/private_person/version.rb +7 -0
  17. data/lib/private_person.rb +14 -0
  18. data/private_person.gemspec +127 -0
  19. data/script/rails +6 -0
  20. data/spec/dummy/.rspec +1 -0
  21. data/spec/dummy/Rakefile +7 -0
  22. data/spec/dummy/app/models/follow.rb +14 -0
  23. data/spec/dummy/app/models/page.rb +4 -0
  24. data/spec/dummy/app/models/user.rb +30 -0
  25. data/spec/dummy/config/application.rb +56 -0
  26. data/spec/dummy/config/boot.rb +10 -0
  27. data/spec/dummy/config/database.yml +25 -0
  28. data/spec/dummy/config/environment.rb +5 -0
  29. data/spec/dummy/config/environments/development.rb +27 -0
  30. data/spec/dummy/config/environments/production.rb +58 -0
  31. data/spec/dummy/config/environments/test.rb +25 -0
  32. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  33. data/spec/dummy/config/initializers/inflections.rb +15 -0
  34. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  35. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  36. data/spec/dummy/config/initializers/session_store.rb +8 -0
  37. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  38. data/spec/dummy/config/locales/devise.en.yml +59 -0
  39. data/spec/dummy/config/locales/en.yml +5 -0
  40. data/spec/dummy/config/routes.rb +59 -0
  41. data/spec/dummy/config.ru +4 -0
  42. data/spec/dummy/db/development.sqlite3 +0 -0
  43. data/spec/dummy/db/migrate/20130906211525_create_permissions_table.rb +18 -0
  44. data/spec/dummy/db/migrate/20130906213557_create_users_table.rb +13 -0
  45. data/spec/dummy/db/migrate/20130906213612_create_pages_table.rb +15 -0
  46. data/spec/dummy/db/migrate/20130907010108_acts_as_follower_migration.rb +17 -0
  47. data/spec/dummy/db/schema.rb +56 -0
  48. data/spec/dummy/db/test.sqlite3 +0 -0
  49. data/spec/dummy/script/rails +6 -0
  50. data/spec/factories/pages.rb +7 -0
  51. data/spec/factories/permissions.rb +7 -0
  52. data/spec/factories/users.rb +5 -0
  53. data/spec/models/page_spec.rb +6 -0
  54. data/spec/models/permission_spec.rb +88 -0
  55. data/spec/models/user_spec.rb +101 -0
  56. data/spec/private_person_spec.rb +7 -0
  57. data/spec/spec_helper.rb +36 -0
  58. data/spec/support/permissions_support.rb +24 -0
  59. data/spec/support/users_support.rb +21 -0
  60. metadata +259 -0
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,27 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+
15
+ # Print deprecation notices to the Rails logger
16
+ config.active_support.deprecation = :log
17
+
18
+ # Only use best-standards-support built into browsers
19
+ config.action_dispatch.best_standards_support = :builtin
20
+
21
+ # Raise exception on mass assignment protection for Active Record models
22
+ config.active_record.mass_assignment_sanitizer = :strict
23
+
24
+ # Log the query plan for queries taking more than this (works
25
+ # with SQLite, MySQL, and PostgreSQL)
26
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
27
+ end
@@ -0,0 +1,58 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+
11
+ # Disable Rails's static asset server (Apache or nginx will already do this)
12
+ config.serve_static_assets = false
13
+
14
+ # Defaults to nil and saved in location specified by config.assets.prefix
15
+ # config.assets.manifest = YOUR_PATH
16
+
17
+ # Specifies the header that your server uses for sending files
18
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
19
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
20
+
21
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
22
+ # config.force_ssl = true
23
+
24
+ # See everything in the log (default is :info)
25
+ # config.log_level = :debug
26
+
27
+ # Prepend all log lines with the following tags
28
+ # config.log_tags = [ :subdomain, :uuid ]
29
+
30
+ # Use a different logger for distributed setups
31
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
32
+
33
+ # Use a different cache store in production
34
+ # config.cache_store = :mem_cache_store
35
+
36
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
37
+ # config.action_controller.asset_host = "http://assets.example.com"
38
+
39
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
40
+ # config.assets.precompile += %w( search.js )
41
+
42
+ # Disable delivery errors, bad email addresses will be ignored
43
+ # config.action_mailer.raise_delivery_errors = false
44
+
45
+ # Enable threaded mode
46
+ # config.threadsafe!
47
+
48
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
49
+ # the I18n.default_locale when a translation can not be found)
50
+ config.i18n.fallbacks = true
51
+
52
+ # Send deprecation notices to registered listeners
53
+ config.active_support.deprecation = :notify
54
+
55
+ # Log the query plan for queries taking more than this (works
56
+ # with SQLite, MySQL, and PostgreSQL)
57
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
58
+ end
@@ -0,0 +1,25 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Configure static asset server for tests with Cache-Control for performance
11
+ config.serve_static_assets = true
12
+ config.static_cache_control = "public, max-age=3600"
13
+
14
+ # Log error messages when you accidentally call methods on nil
15
+ config.whiny_nils = true
16
+
17
+ # Show full error reports and disable caching
18
+ config.consider_all_requests_local = true
19
+
20
+ # Raise exception on mass assignment protection for Active Record models
21
+ config.active_record.mass_assignment_sanitizer = :strict
22
+
23
+ # Print deprecation notices to the stderr
24
+ config.active_support.deprecation = :stderr
25
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,15 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
11
+ #
12
+ # These inflection rules are supported but not enabled by default:
13
+ # ActiveSupport::Inflector.inflections do |inflect|
14
+ # inflect.acronym 'RESTful'
15
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = '13335d67552fdd1870f1e89aa229a259979c25ad14a60a64b75ce77db7622c9728606f2415d021416725905e8ad5955be6fff9e01702167f1ddc0fb4c5f3cfdf'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters :format => [:json]
9
+ end
10
+
11
+ # Disable root element in JSON by default.
12
+ ActiveSupport.on_load(:active_record) do
13
+ self.include_root_in_json = false
14
+ end
@@ -0,0 +1,59 @@
1
+ # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2
+
3
+ en:
4
+ devise:
5
+ confirmations:
6
+ confirmed: "Your account was successfully confirmed. You are now signed in."
7
+ send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes."
8
+ send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."
9
+ failure:
10
+ already_authenticated: "You are already signed in."
11
+ inactive: "Your account was not activated yet."
12
+ invalid: "Invalid email or password."
13
+ invalid_token: "Invalid authentication token."
14
+ locked: "Your account is locked."
15
+ not_found_in_database: "Invalid email or password."
16
+ timeout: "Your session expired, please sign in again to continue."
17
+ unauthenticated: "You need to sign in or sign up before continuing."
18
+ unconfirmed: "You have to confirm your account before continuing."
19
+ mailer:
20
+ confirmation_instructions:
21
+ subject: "Confirmation instructions"
22
+ reset_password_instructions:
23
+ subject: "Reset password instructions"
24
+ unlock_instructions:
25
+ subject: "Unlock Instructions"
26
+ omniauth_callbacks:
27
+ failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
28
+ success: "Successfully authenticated from %{kind} account."
29
+ passwords:
30
+ no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
31
+ send_instructions: "You will receive an email with instructions about how to reset your password in a few minutes."
32
+ send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
33
+ updated: "Your password was changed successfully. You are now signed in."
34
+ updated_not_active: "Your password was changed successfully."
35
+ registrations:
36
+ destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon."
37
+ signed_up: "Welcome! You have signed up successfully."
38
+ signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
39
+ signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
40
+ signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account."
41
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
42
+ updated: "You updated your account successfully."
43
+ sessions:
44
+ signed_in: "Signed in successfully."
45
+ signed_out: "Signed out successfully."
46
+ unlocks:
47
+ send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes."
48
+ send_paranoid_instructions: "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes."
49
+ unlocked: "Your account has been unlocked successfully. Please sign in to continue."
50
+ errors:
51
+ messages:
52
+ already_confirmed: "was already confirmed, please try signing in"
53
+ confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
54
+ expired: "has expired, please request a new one"
55
+ not_found: "not found"
56
+ not_locked: "was not locked"
57
+ not_saved:
58
+ one: "1 error prohibited this %{resource} from being saved:"
59
+ other: "%{count} errors prohibited this %{resource} from being saved:"
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,59 @@
1
+ Dummy::Application.routes.draw do
2
+
3
+ # The priority is based upon order of creation:
4
+ # first created -> highest priority.
5
+
6
+ # Sample of regular route:
7
+ # match 'products/:id' => 'catalog#view'
8
+ # Keep in mind you can assign values other than :controller and :action
9
+
10
+ # Sample of named route:
11
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
12
+ # This route can be invoked with purchase_url(:id => product.id)
13
+
14
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
15
+ # resources :products
16
+
17
+ # Sample resource route with options:
18
+ # resources :products do
19
+ # member do
20
+ # get 'short'
21
+ # post 'toggle'
22
+ # end
23
+ #
24
+ # collection do
25
+ # get 'sold'
26
+ # end
27
+ # end
28
+
29
+ # Sample resource route with sub-resources:
30
+ # resources :products do
31
+ # resources :comments, :sales
32
+ # resource :seller
33
+ # end
34
+
35
+ # Sample resource route with more complex sub-resources
36
+ # resources :products do
37
+ # resources :comments
38
+ # resources :sales do
39
+ # get 'recent', :on => :collection
40
+ # end
41
+ # end
42
+
43
+ # Sample resource route within a namespace:
44
+ # namespace :admin do
45
+ # # Directs /admin/products/* to Admin::ProductsController
46
+ # # (app/controllers/admin/products_controller.rb)
47
+ # resources :products
48
+ # end
49
+
50
+ # You can have the root of your site routed with "root"
51
+ # just remember to delete public/index.html.
52
+ # root :to => 'welcome#index'
53
+
54
+ # See how all your routes lay out with "rake routes"
55
+
56
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
57
+ # Note: This route will make all actions in every controller accessible via GET requests.
58
+ # match ':controller(/:action(/:id))(.:format)'
59
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
Binary file
@@ -0,0 +1,18 @@
1
+ class CreatePermissionsTable < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :permissions do |t|
4
+ t.string :permissor_type
5
+ t.integer :permissor_id
6
+ t.string :permissible_type
7
+ t.integer :permissible_id
8
+ t.string :relationship_type, :default => 'none'
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :permissions, [:permissor_type, :permissor_id]
13
+ add_index :permissions, [:permissible_type, :permissible_id]
14
+ end
15
+ def self.down
16
+ drop_table :permissions
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ class CreateUsersTable < ActiveRecord::Migration
2
+ def up
3
+ create_table :users do |t|
4
+ t.string :nickname
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+
10
+ def down
11
+ drop_table :users
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ class CreatePagesTable < ActiveRecord::Migration
2
+ def up
3
+ create_table :pages do |t|
4
+ t.string :title
5
+ t.text :body
6
+ t.references :user
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def down
13
+ drop_table :pages
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ class ActsAsFollowerMigration < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :follows, :force => true do |t|
4
+ t.references :followable, :polymorphic => true, :null => false
5
+ t.references :follower, :polymorphic => true, :null => false
6
+ t.boolean :blocked, :default => false, :null => false
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :follows, ["follower_id", "follower_type"], :name => "fk_follows"
11
+ add_index :follows, ["followable_id", "followable_type"], :name => "fk_followables"
12
+ end
13
+
14
+ def self.down
15
+ drop_table :follows
16
+ end
17
+ end
@@ -0,0 +1,56 @@
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 to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20130907010108) do
15
+
16
+ create_table "follows", :force => true do |t|
17
+ t.integer "followable_id", :null => false
18
+ t.string "followable_type", :null => false
19
+ t.integer "follower_id", :null => false
20
+ t.string "follower_type", :null => false
21
+ t.boolean "blocked", :default => false, :null => false
22
+ t.datetime "created_at", :null => false
23
+ t.datetime "updated_at", :null => false
24
+ end
25
+
26
+ add_index "follows", ["followable_id", "followable_type"], :name => "fk_followables"
27
+ add_index "follows", ["follower_id", "follower_type"], :name => "fk_follows"
28
+
29
+ create_table "pages", :force => true do |t|
30
+ t.string "title"
31
+ t.text "body"
32
+ t.integer "user_id"
33
+ t.datetime "created_at", :null => false
34
+ t.datetime "updated_at", :null => false
35
+ end
36
+
37
+ create_table "permissions", :force => true do |t|
38
+ t.string "permissor_type"
39
+ t.integer "permissor_id"
40
+ t.string "permissible_type"
41
+ t.integer "permissible_id"
42
+ t.string "relationship_type", :default => "none"
43
+ t.datetime "created_at", :null => false
44
+ t.datetime "updated_at", :null => false
45
+ end
46
+
47
+ add_index "permissions", ["permissible_type", "permissible_id"], :name => "index_permissions_on_permissible_type_and_permissible_id"
48
+ add_index "permissions", ["permissor_type", "permissor_id"], :name => "index_permissions_on_permissor_type_and_permissor_id"
49
+
50
+ create_table "users", :force => true do |t|
51
+ t.string "nickname"
52
+ t.datetime "created_at", :null => false
53
+ t.datetime "updated_at", :null => false
54
+ end
55
+
56
+ end
Binary file
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby1.8
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :page, :aliases => [:permissible] do
3
+ sequence(:title) {|n| "page#{n}" }
4
+ body 'Lorem Ipsum, baby'
5
+ user
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :permission do
3
+ relationship_type 'none'
4
+ permissible
5
+ permissor
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :user, :aliases => [:permissor] do
3
+ sequence(:nickname) {|n| "person#{n}" }
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe Page do
4
+ it { should have_many(:permissions) }
5
+ it { should have_many(:permissors) }
6
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe Permission do
4
+ # Check relationships
5
+ it { should belong_to(:permissor) }
6
+ it { should belong_to(:permissible) }
7
+
8
+ # Check accessible attributes
9
+ it { should allow_mass_assignment_of(:permissible) }
10
+ it { should allow_mass_assignment_of(:permissible_type) }
11
+ it { should allow_mass_assignment_of(:permissible_id) }
12
+ it { should allow_mass_assignment_of(:relationship_type) }
13
+
14
+ # Check validations
15
+ it { should validate_presence_of(:permissor) }
16
+ it { should validate_presence_of(:permissible_type) }
17
+ it { should validate_presence_of(:relationship_type) }
18
+
19
+ describe 'Class Methods' do
20
+ include_context 'permissions support'
21
+
22
+ describe '.find_all_by_permissor' do
23
+ subject { Permission.find_all_by_permissor(followed_user) }
24
+ it { should have_exactly(8).items }
25
+ it { should include general_permission }
26
+ it { should include following_users_permission }
27
+ it { should include user_followers_permission }
28
+ it { should include follower_of_followers_permission }
29
+ it { should include following_of_followings_permission }
30
+ it { should include public_permission }
31
+ it { should include none_permission }
32
+ it { should include forbidden_permission }
33
+ end
34
+
35
+ describe '.find_all_by_permissible' do
36
+ subject { Permission.find_all_by_permissible(following_page) }
37
+ it { should eq [following_users_permission]}
38
+ end
39
+
40
+ describe '.find_all_by_wildcard' do
41
+ subject { Permission.find_all_by_wildcard('Page') }
42
+ it { should eq [general_permission] }
43
+ end
44
+
45
+ describe '.find_all_by_relationship_type' do
46
+ subject { Permission.find_all_by_relationship_type('following_users') }
47
+ it { should have_exactly(3).items }
48
+ it { should include general_permission }
49
+ it { should include following_users_permission }
50
+ it { should include public_permission }
51
+ end
52
+
53
+ describe '.blocked' do
54
+ subject { Permission.blocked }
55
+ it { should have_exactly(2).items }
56
+ it { should include none_permission }
57
+ it { should include forbidden_permission }
58
+ end
59
+
60
+ describe '.legitimate' do
61
+ subject { Permission.legitimate }
62
+ it { should have_exactly(6).items }
63
+ it { should include general_permission }
64
+ it { should include following_users_permission }
65
+ it { should include user_followers_permission }
66
+ it { should include follower_of_followers_permission }
67
+ it { should include following_of_followings_permission }
68
+ it { should include public_permission }
69
+ end
70
+
71
+ describe '.permissible_types' do
72
+ subject { Permission.permissible_types.sort }
73
+ it { should be_an Array }
74
+ it { should eq %w{following_users user_followers following_of_followings follower_of_followers public}.sort }
75
+ end
76
+ end
77
+
78
+ describe 'Instance Methods' do
79
+ include_context 'permissions support'
80
+
81
+ describe '#existing_types' do
82
+ subject { following_users_permission.existing_types.sort }
83
+ it { should be_an Array }
84
+ it { should eq %w{following_users user_followers following_of_followings follower_of_followers public}.sort }
85
+ end
86
+ end
87
+
88
+ end