spec/spec_helpers/model.rb in protector-0.0.1 vs spec/spec_helpers/model.rb in protector-0.0.2
- old
+ new
@@ -37,29 +37,55 @@
meta.access[:view].should == fields
meta.access[:create].should == fields
meta.access[:update].should == fields
end
+ describe "association" do
+ context "(has_many)" do
+ it "passes subject" do
+ Dummy.first.restrict('!').fluffies.protector_subject.should == '!'
+ end
+ end
+
+ context "(belongs_to)" do
+ it "passes subject" do
+ Fluffy.first.restrict('!').dummy.protector_subject.should == '!'
+ end
+ end
+ end
+
describe "visibility" do
it "marks blocked" do
@dummy.instance_eval do
- protect do
- scope { none }
- end
+ protect do; scope { none }; end
end
@dummy.first.restrict('!').visible?.should == false
end
it "marks allowed" do
@dummy.instance_eval do
+ protect do; scope { limit(5) }; end
+ end
+
+ @dummy.first.restrict('!').visible?.should == true
+ end
+ end
+
+ describe "readability" do
+ it "hides fields" do
+ @dummy.instance_eval do
protect do
- scope { limit(5) }
+ can :view, :string
end
end
- @dummy.first.restrict('!').visible?.should == true
+ dummy = @dummy.first.restrict('!')
+ dummy.number.should == nil
+ dummy[:number].should == nil
+ dummy.read_attribute(:number).should_not == nil
+ dummy.string.should == 'zomgstring'
end
end
describe "creatability" do
context "with empty meta" do
@@ -72,14 +98,14 @@
it "marks blocked" do
dummy = @dummy.new(string: 'bam', number: 1)
dummy.restrict('!').creatable?.should == false
end
- it "invalidates" do
- dummy = @dummy.new(string: 'bam', number: 1).restrict('!')
- dummy.should invalidate
- end
+ # it "invalidates" do
+ # dummy = @dummy.new(string: 'bam', number: 1).restrict('!')
+ # dummy.should invalidate
+ # end
end
context "by list of fields" do
before(:each) do
@dummy.instance_eval do
@@ -97,14 +123,14 @@
it "marks allowed" do
dummy = @dummy.new(string: 'bam')
dummy.restrict('!').creatable?.should == true
end
- it "invalidates" do
- dummy = @dummy.new(string: 'bam', number: 1).restrict('!')
- dummy.should invalidate
- end
+ # it "invalidates" do
+ # dummy = @dummy.new(string: 'bam', number: 1).restrict('!')
+ # dummy.should invalidate
+ # end
it "validates" do
dummy = @dummy.new(string: 'bam').restrict('!')
dummy.should validate
end
@@ -112,11 +138,11 @@
context "by lambdas" do
before(:each) do
@dummy.instance_eval do
protect do
- can :create, string: -> (x) { x.length == 5 }
+ can :create, string: -> (x) { x.try(:length) == 5 }
end
end
end
it "marks blocked" do
@@ -127,14 +153,14 @@
it "marks allowed" do
dummy = @dummy.new(string: '12345')
dummy.restrict('!').creatable?.should == true
end
- it "invalidates" do
- dummy = @dummy.new(string: 'bam').restrict('!')
- dummy.should invalidate
- end
+ # it "invalidates" do
+ # dummy = @dummy.new(string: 'bam').restrict('!')
+ # dummy.should invalidate
+ # end
it "validates" do
dummy = @dummy.new(string: '12345').restrict('!')
dummy.should validate
end
@@ -157,14 +183,14 @@
it "marks allowed" do
dummy = @dummy.new(number: 2)
dummy.restrict('!').creatable?.should == true
end
- it "invalidates" do
- dummy = @dummy.new(number: 500).restrict('!')
- dummy.should invalidate
- end
+ # it "invalidates" do
+ # dummy = @dummy.new(number: 500).restrict('!')
+ # dummy.should invalidate
+ # end
it "validates" do
dummy = @dummy.new(number: 2).restrict('!')
dummy.should validate
end
@@ -228,11 +254,11 @@
context "by lambdas" do
before(:each) do
@dummy.instance_eval do
protect do
- can :update, string: -> (x) { x.length == 5 }
+ can :update, string: -> (x) { x.try(:length) == 5 }
end
end
end
it "marks blocked" do
@@ -324,10 +350,10 @@
@dummy.instance_eval do
protect do; can :destroy; end
end
dummy = @dummy.create!.restrict('!')
- dummy.destroy.should == dummy
+ dummy.destroy!.should == dummy
dummy.destroyed?.should == true
end
end
end
\ No newline at end of file