Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add basic testing framework.

  • Loading branch information...
commit eb48c15ad4fe9fc9580196d19869b81e42076d20 1 parent a943ce1
Mitch Crowe authored
1  .rspec
View
@@ -0,0 +1 @@
+--color
12 README.md
View
@@ -26,27 +26,27 @@ And then run the migrations:
## Setup
-Include `Roleable::Subject` into your user (subject) model, e.g.:
+Include `Roleable::RoleSubject` into your user (subject) model, e.g.:
```ruby
class User < ActiveRecord::Base
- include Roleable::Subject
+ include Roleable::RoleSubject
...
end
```
-Include `Roleable::Object` into any models you want to relate a user role to (objects), e.g.:
+Include `Roleable::RoleObject` into any models you want to relate a user role to (objects), e.g.:
```ruby
class Page < ActiveRecord::Base
- include Roleable::Object
+ include Roleable::RoleObject
...
end
```
## Usage
-### Subject
+### RoleSubject
Add a role:
@@ -93,7 +93,7 @@ user.roles_for_object(Page.last)
user.roles_for_object(nil)
```
-### Object
+### RoleObject
Get users with a given role for an object:
6 Rakefile
View
@@ -1,2 +1,6 @@
#!/usr/bin/env rake
-require "bundler/gem_tasks"
+require 'bundler/gem_tasks'
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec)
+task :default => :spec
8 lib/roleable.rb
View
@@ -1,5 +1,3 @@
-require "roleable/version"
-
-module Roleable
- # Your code goes here...
-end
+require 'roleable/version'
+require 'roleable/subject'
+require 'roleable/object'
2  lib/roleable/object.rb
View
@@ -0,0 +1,2 @@
+module Roleable::RoleObject
+end
9 lib/roleable/subject.rb
View
@@ -0,0 +1,9 @@
+module Roleable::RoleSubject
+ def self.test
+ true
+ end
+
+ def add_role(role, object)
+ true
+ end
+end
7 roleable.gemspec
View
@@ -14,4 +14,11 @@ Gem::Specification.new do |gem|
gem.name = "roleable"
gem.require_paths = ["lib"]
gem.version = Roleable::VERSION
+
+ gem.add_development_dependency 'rake'
+ gem.add_development_dependency 'rspec', '~> 2.8'
+ gem.add_development_dependency 'sqlite3'
+ gem.add_development_dependency 'activerecord', '~> 3.0.9'
+ gem.add_development_dependency 'with_model'
+
end
54 spec/roleable/subject_spec.rb
View
@@ -0,0 +1,54 @@
+require 'spec_helper'
+
+ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
+
+describe Roleable::RoleSubject do
+
+ with_model :User do
+ table do |t|
+ t.string :name
+ end
+
+ model do
+ include Roleable::RoleSubject
+ end
+ end
+
+ with_model :Page do
+ table do |t|
+ t.string :title
+ end
+
+ model do
+ include Roleable::RoleObject
+ end
+ end
+
+ with_model :Role do
+ table do |t|
+ t.string :name
+ end
+ end
+
+ with_model :UserRole do
+ table do |t|
+ t.integer :user_id
+ t.integer :role_id
+ t.integer :object_id
+ t.string :object_type
+ end
+
+ model do
+ belongs_to :user
+ belongs_to :role
+ belongs_to :object, :polymorphic => true
+ end
+ end
+
+ describe '#test' do
+ it 'is true' do
+ Roleable::RoleSubject.test.should be_true
+ end
+ end
+
+end
11 spec/spec_helper.rb
View
@@ -0,0 +1,11 @@
+require 'rubygems'
+require 'bundler/setup'
+
+require 'sqlite3'
+require 'active_record'
+require 'with_model'
+require 'roleable'
+
+RSpec.configure do |config|
+ config.extend WithModel
+end
Please sign in to comment.
Something went wrong with that request. Please try again.