From 9c87cf49908c468c41e53d8cbbe6f432268e8d46 Mon Sep 17 00:00:00 2001 From: Frank Macreery Date: Tue, 17 Sep 2013 12:29:38 -0400 Subject: [PATCH] Attempt to recreate bug cited by @monfresh in #53 --- spec/integration/grape_spec.rb | 38 ++++++++++++++++++++++++++++++++ spec/integration/mongoid_spec.rb | 25 +++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/spec/integration/grape_spec.rb b/spec/integration/grape_spec.rb index 101d21b..1568b39 100644 --- a/spec/integration/grape_spec.rb +++ b/spec/integration/grape_spec.rb @@ -24,10 +24,48 @@ class TestGrapeApp < Grape::API { :meaning_of_life => 42 }.to_json end end + + get "/mongers" do + garner.options({ :expires_in => 5.minutes }) do + Monger.all + end + end end TestGrapeApp.new end it_behaves_like "Rack::ConditionalGet server" + + context "caching modified classes/objects" do + include Rack::Test::Methods + + before(:each) do + @object = Monger.create!({ :name => "M1" }) + end + + it "does not raise error when underlying classes are changed" do + json = Monger.all.to_json + browser = Rack::Test::Session.new(TestGrapeApp.new) + browser.get "/mongers" + browser.last_response.should be_successful + browser.last_response.body.should == json + + TestGrapeApp.reset! + class TestGrapeApp < Grape::API + helpers Garner::Mixins::Rack + + format :json + + get "/mongers" do + Monger.all + end + end + + browser = Rack::Test::Session.new(TestGrapeApp.new) + browser.get "/mongers" + browser.last_response.should be_successful + browser.last_response.body.should == json + end + end end diff --git a/spec/integration/mongoid_spec.rb b/spec/integration/mongoid_spec.rb index 9473d97..4ab4e1f 100644 --- a/spec/integration/mongoid_spec.rb +++ b/spec/integration/mongoid_spec.rb @@ -237,6 +237,31 @@ end end end + + context "caching modified classes/objects" do + before(:each) do + @object = Monger.create!({ :name => "M1" }) + end + + let(:cached_object_fetcher) do + lambda do + @app.garner.options({ :expires_in => 5.minutes }) do + Monger.all.as_json + end + end + end + + it "does not raise error when underlying classes are changed" do + json = Monger.all.as_json + cached_object_fetcher.call.should == json + + class Monger + field :foo, :type => Boolean + end + + cached_object_fetcher.call.should == json + end + end end end end