disabling MetaWhere feature and making Acitve Record fixture that is always loaded
This commit is contained in:
parent
8c72ab40a4
commit
1ff1b70de4
2
Gemfile
2
Gemfile
|
@ -4,8 +4,6 @@ case ENV["MODEL_ADAPTER"]
|
||||||
when nil, "active_record"
|
when nil, "active_record"
|
||||||
gem "sqlite3"
|
gem "sqlite3"
|
||||||
gem "activerecord", '~> 3.0.9', :require => "active_record"
|
gem "activerecord", '~> 3.0.9', :require => "active_record"
|
||||||
gem "with_model", '~> 0.1.5'
|
|
||||||
gem "meta_where"
|
|
||||||
when "data_mapper"
|
when "data_mapper"
|
||||||
gem "dm-core", "~> 1.0.2"
|
gem "dm-core", "~> 1.0.2"
|
||||||
gem "dm-sqlite-adapter", "~> 1.0.2"
|
gem "dm-sqlite-adapter", "~> 1.0.2"
|
||||||
|
|
|
@ -2,6 +2,8 @@ require "spec_helper"
|
||||||
|
|
||||||
describe CanCan::ControllerResource do
|
describe CanCan::ControllerResource do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
Project.delete_all
|
||||||
|
Category.delete_all
|
||||||
@params = HashWithIndifferentAccess.new(:controller => "projects")
|
@params = HashWithIndifferentAccess.new(:controller => "projects")
|
||||||
@controller_class = Class.new
|
@controller_class = Class.new
|
||||||
@controller = @controller_class.new
|
@controller = @controller_class.new
|
||||||
|
@ -70,6 +72,9 @@ describe CanCan::ControllerResource do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not build a collection when on index action when class does not respond to accessible_by and not mark ability as fully authorized" do
|
it "does not build a collection when on index action when class does not respond to accessible_by and not mark ability as fully authorized" do
|
||||||
|
class CustomModel
|
||||||
|
end
|
||||||
|
@params[:controller] = "custom_models"
|
||||||
@params[:action] = "index"
|
@params[:action] = "index"
|
||||||
CanCan::ControllerResource.new(@controller, :load => true).process
|
CanCan::ControllerResource.new(@controller, :load => true).process
|
||||||
@controller.instance_variable_get(:@project).should be_nil
|
@controller.instance_variable_get(:@project).should be_nil
|
||||||
|
|
|
@ -1,42 +1,7 @@
|
||||||
if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record"
|
if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record"
|
||||||
require "spec_helper"
|
require "spec_helper"
|
||||||
|
|
||||||
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
|
||||||
|
|
||||||
describe CanCan::ModelAdapters::ActiveRecordAdapter do
|
describe CanCan::ModelAdapters::ActiveRecordAdapter do
|
||||||
with_model :category do
|
|
||||||
table do |t|
|
|
||||||
t.boolean "visible"
|
|
||||||
end
|
|
||||||
model do
|
|
||||||
has_many :articles
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
with_model :article do
|
|
||||||
table do |t|
|
|
||||||
t.string "name"
|
|
||||||
t.boolean "published"
|
|
||||||
t.boolean "secret"
|
|
||||||
t.integer "priority"
|
|
||||||
t.integer "category_id"
|
|
||||||
end
|
|
||||||
model do
|
|
||||||
belongs_to :category
|
|
||||||
has_many :comments
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
with_model :comment do
|
|
||||||
table do |t|
|
|
||||||
t.boolean "spam"
|
|
||||||
t.integer "article_id"
|
|
||||||
end
|
|
||||||
model do
|
|
||||||
belongs_to :article
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
Article.delete_all
|
Article.delete_all
|
||||||
Comment.delete_all
|
Comment.delete_all
|
||||||
|
@ -229,6 +194,7 @@ if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "restricts articles given a MetaWhere condition" do
|
it "restricts articles given a MetaWhere condition" do
|
||||||
|
pending
|
||||||
@ability.can :read, :articles, :priority.lt => 2
|
@ability.can :read, :articles, :priority.lt => 2
|
||||||
article1 = Article.create!(:priority => 1)
|
article1 = Article.create!(:priority => 1)
|
||||||
article2 = Article.create!(:priority => 3)
|
article2 = Article.create!(:priority => 3)
|
||||||
|
@ -238,6 +204,7 @@ if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "matches any MetaWhere condition" do
|
it "matches any MetaWhere condition" do
|
||||||
|
pending
|
||||||
adapter = CanCan::ModelAdapters::ActiveRecordAdapter
|
adapter = CanCan::ModelAdapters::ActiveRecordAdapter
|
||||||
article1 = Article.new(:priority => 1, :name => "Hello World")
|
article1 = Article.new(:priority => 1, :name => "Hello World")
|
||||||
adapter.matches_condition?(article1, :priority.eq, 1).should be_true
|
adapter.matches_condition?(article1, :priority.eq, 1).should be_true
|
||||||
|
|
37
spec/fixtures/active_record.rb
vendored
Normal file
37
spec/fixtures/active_record.rb
vendored
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
||||||
|
|
||||||
|
class Category < ActiveRecord::Base
|
||||||
|
connection.create_table(table_name) do |t|
|
||||||
|
t.boolean :visible
|
||||||
|
end
|
||||||
|
has_many :articles
|
||||||
|
has_many :projects
|
||||||
|
end
|
||||||
|
|
||||||
|
class Project < ActiveRecord::Base
|
||||||
|
connection.create_table(table_name) do |t|
|
||||||
|
t.integer :category_id
|
||||||
|
t.string :name
|
||||||
|
end
|
||||||
|
belongs_to :category
|
||||||
|
end
|
||||||
|
|
||||||
|
class Article < ActiveRecord::Base
|
||||||
|
connection.create_table(table_name) do |t|
|
||||||
|
t.integer :category_id
|
||||||
|
t.string :name
|
||||||
|
t.boolean :published
|
||||||
|
t.boolean :secret
|
||||||
|
t.integer :priority
|
||||||
|
end
|
||||||
|
belongs_to :category
|
||||||
|
has_many :comments
|
||||||
|
end
|
||||||
|
|
||||||
|
class Comment < ActiveRecord::Base
|
||||||
|
connection.create_table(table_name) do |t|
|
||||||
|
t.integer :article_id
|
||||||
|
t.boolean :spam
|
||||||
|
end
|
||||||
|
belongs_to :article
|
||||||
|
end
|
0
spec/fixtures/data_mapper.rb
vendored
Normal file
0
spec/fixtures/data_mapper.rb
vendored
Normal file
0
spec/fixtures/mongoid.rb
vendored
Normal file
0
spec/fixtures/mongoid.rb
vendored
Normal file
|
@ -3,21 +3,16 @@ require 'bundler/setup'
|
||||||
|
|
||||||
Bundler.require(:default)
|
Bundler.require(:default)
|
||||||
|
|
||||||
require 'supermodel' # shouldn't Bundler do this already?
|
|
||||||
require 'active_support/all'
|
require 'active_support/all'
|
||||||
require 'matchers'
|
require 'matchers'
|
||||||
require 'cancan/matchers'
|
require 'cancan/matchers'
|
||||||
|
|
||||||
|
require File.expand_path('../fixtures/active_record', __FILE__)
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.treat_symbols_as_metadata_keys_with_true_values = true
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
||||||
config.filter_run :focus => true
|
config.filter_run :focus => true
|
||||||
config.run_all_when_everything_filtered = true
|
config.run_all_when_everything_filtered = true
|
||||||
|
|
||||||
config.before(:each) do
|
|
||||||
Project.delete_all
|
|
||||||
Category.delete_all
|
|
||||||
end
|
|
||||||
config.extend WithModel
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Ability
|
class Ability
|
||||||
|
@ -26,20 +21,3 @@ class Ability
|
||||||
def initialize(user)
|
def initialize(user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Category < SuperModel::Base
|
|
||||||
has_many :projects
|
|
||||||
end
|
|
||||||
|
|
||||||
class Project < SuperModel::Base
|
|
||||||
belongs_to :category
|
|
||||||
attr_accessor :category # why doesn't SuperModel do this automatically?
|
|
||||||
|
|
||||||
def self.respond_to?(method, include_private = false)
|
|
||||||
if method.to_s == "find_by_name!" # hack to simulate ActiveRecord
|
|
||||||
true
|
|
||||||
else
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user