Permalink
Browse files

implemented search view

  • Loading branch information...
1 parent 9bca304 commit 5aa54d1fa101e419bb62da08f29e5cd4c805b68a @phifty committed Oct 19, 2011
View
@@ -1,6 +1,7 @@
require 'rspec'
require File.join(File.dirname(__FILE__), "spec", "acceptance", "adapter_that_needs_setup")
+require File.join(File.dirname(__FILE__), "spec", "acceptance", "adapter_with_search")
require File.join(File.dirname(__FILE__), "spec", "acceptance", "adapter_with_stateful_storage")
require File.join(File.dirname(__FILE__), "spec", "acceptance", "read_only_adapter_with_stateless_storage")
@@ -0,0 +1,47 @@
+
+shared_examples_for "an adapter with search view" do
+
+ before :all do
+ GOM::Storage.setup
+ end
+
+ after :all do
+ GOM::Storage.teardown
+ end
+
+ before :each do
+ @object_one = GOM::Spec::Object.new
+ @object_one.number = 11
+
+ @object_two = GOM::Spec::Object.new
+ @object_two.number = 24
+
+ @object_three = Object.new
+ @object_three.instance_variable_set :@number, 11
+ end
+
+ describe "fetching a search collection" do
+
+ before :each do
+ GOM::Storage.store @object_one, :test_storage
+ GOM::Storage.store @object_two, :test_storage
+
+ sleep 1.0 # wait until changes go through the river in the index
+ end
+
+ after :each do
+ GOM::Storage.remove @object_one
+ GOM::Storage.remove @object_two
+ end
+
+ it "should return the right results" do
+ collection = GOM::Storage.collection :test_storage, :test_search_view, :query => "11"
+ collection.should be_instance_of(GOM::Object::Collection)
+ collection.size.should == 1
+ collection.map(&:class).should == [ GOM::Spec::Object ]
+ collection.map(&:number).should == [ 11 ]
+ end
+
+ end
+
+end
@@ -105,6 +105,10 @@ def self.property_view(hash)
View::Property.new *hash.values_at(:filter, :properties)
end
+ def self.search_view(hash)
+ View::Search.new hash[:model_class]
+ end
+
def self.setup_all
@configurations.values.each do |configuration|
configuration.setup
@@ -5,5 +5,6 @@ module GOM::Storage::Configuration::View
autoload :Class, File.join(File.dirname(__FILE__), "view", "class")
autoload :MapReduce, File.join(File.dirname(__FILE__), "view", "map_reduce")
autoload :Property, File.join(File.dirname(__FILE__), "view", "property")
+ autoload :Search, File.join(File.dirname(__FILE__), "view", "search")
end
@@ -0,0 +1,11 @@
+
+# Contains all the parameters for a search view.
+class GOM::Storage::Configuration::View::Search
+
+ attr_accessor :class_name
+
+ def initialize(class_name)
+ @class_name = class_name
+ end
+
+end
@@ -0,0 +1,17 @@
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "..", "..", "spec_helper"))
+
+describe GOM::Storage::Configuration::View::Search do
+
+ before :each do
+ @view = described_class.new [ "Object" ]
+ end
+
+ describe "initialize" do
+
+ it "should set the view's class name" do
+ @view.class_name.should == [ "Object" ]
+ end
+
+ end
+
+end

0 comments on commit 5aa54d1

Please sign in to comment.