spec/draper/base_spec.rb in draper-0.16.0 vs spec/draper/base_spec.rb in draper-0.17.0
- old
+ new
@@ -176,10 +176,27 @@
end
it "causes the association's method to return nil" do
subject.previous_version.should be_nil
end
end
+
+ context "#find" do
+ before(:each){ subject.class_eval{ decorates_association :similar_products } }
+ context "with a block" do
+ it "delegates to #each" do
+ subject.similar_products.source.should_receive :find
+ subject.similar_products.find {|p| p.title == "title" }
+ end
+ end
+
+ context "without a block" do
+ it "calls a finder method" do
+ subject.similar_products.source.should_not_receive :find
+ subject.similar_products.find 1
+ end
+ end
+ end
end
context('.decorates_associations') do
subject { Decorator }
it "decorates each of the associations" do
@@ -688,9 +705,72 @@
expect {using_allows_then_denies}.to raise_error(ArgumentError)
end
it "raise an exception for calling denies then allows" do
expect {using_denies_then_allows}.to raise_error(ArgumentError)
+ end
+ end
+
+ describe "a sample usage with denies_all" do
+ let(:subject_with_denies_all){ DecoratorWithDeniesAll.new(source) }
+
+ [:goodnight_moon, :hello_world, :title].each do |method|
+ it "does echo #{method} method" do
+ subject_with_denies_all.should_not respond_to(method)
+ end
+ end
+
+ let(:using_denies_all_then_denies_all) {
+ class DecoratorWithDeniesAllAndDeniesAll < Draper::Base
+ denies_all
+ denies_all
+ end
+ }
+
+ it "allows multple calls to .denies_all" do
+ expect { using_denies_all_then_denies_all }.to_not raise_error(ArgumentError)
+ end
+ end
+
+ describe "invalid usages of denies_all" do
+ let(:using_allows_then_denies_all) {
+ class DecoratorWithAllowsAndDeniesAll < Draper::Base
+ allows :hello_world
+ denies_all
+ end
+ }
+ let(:using_denies_then_denies_all) {
+ class DecoratorWithDeniesAndDeniesAll < Draper::Base
+ denies :goodnight_moon
+ denies_all
+ end
+ }
+ let(:using_denies_all_then_allows) {
+ class DecoratorWithDeniesAllAndAllows < Draper::Base
+ denies_all
+ allows :hello_world
+ end
+ }
+ let(:using_denies_all_then_denies) {
+ class DecoratorWithDeniesAllAndDenies < Draper::Base
+ denies_all
+ denies :goodnight_moon
+ end
+ }
+ it "raises an exception when calling allows then denies_all" do
+ expect {using_allows_then_denies_all}.to raise_error(ArgumentError)
+ end
+
+ it "raises an exception when calling denies then denies_all" do
+ expect {using_denies_then_denies_all}.to raise_error(ArgumentError)
+ end
+
+ it "raises an exception when calling denies_all then allows" do
+ expect {using_denies_all_then_allows}.to raise_error(ArgumentError)
+ end
+
+ it "raises an exception when calling denies_all then denies" do
+ expect {using_denies_all_then_denies}.to raise_error(ArgumentError)
end
end
context "in a Rails application" do
let(:decorator){ DecoratorWithApplicationHelper.decorate(Object.new) }