spec/rapidash/resourceable_spec.rb in rapidash-0.2.0 vs spec/rapidash/resourceable_spec.rb in rapidash-0.2.1

- old
+ new

@@ -118,11 +118,11 @@ it "should add a method with the name of the argument" do Rapidash::ClientTester.new.methods.map { |m| m.to_sym }.should include(:users) end it "should not fail when presented with a multi-word resource" do - expect { + expect { class ClientTester resource :admin_users end }.to_not raise_error(NameError) end @@ -203,34 +203,57 @@ def initialize(*args) end end end - module Its - module A - class DeepResource + module SomeModule + module SomeSubModule + class User def initialize(*args) end end + + class Post + def initialize(*args) + end + end end end class ModuleTester include Rapidash::Resourceable resource :users, :class_name => "Facebook::User" resource :posts, :class_name => Facebook::Posts - resource :deep_resources, :class_name => Its::A::DeepResource + resource :deep_users, :class_name => "SomeModule::SomeSubModule::User" + resource :deep_posts, :class_name => SomeModule::SomeSubModule::Post end it "should find user in another module" do ModuleTester.new.users.class.should eql(Facebook::User) end it "should allow a plural class name" do ModuleTester.new.posts.class.should eql(Facebook::Posts) end - it "should find deep_resource in a nested module" do - ModuleTester.new.deep_resources.class.should eql(Its::A::DeepResource) + it "should find deep_users in a nested module" do + ModuleTester.new.deep_users.class.should eql(SomeModule::SomeSubModule::User) end + + it "should find deep_posts in a nested class name" do + ModuleTester.new.deep_posts.class.should eql(SomeModule::SomeSubModule::Post) + end + + it "should not raise a wrong constant NameError" do + expect { + module Deep + module ModuleTester + class MyResource < Rapidash::Base + resource :users, :class_name => "Facebook::User" + end + end + end + }.to_not raise_error(NameError) + end + end end