forked from clayallsopp/remote_model
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make custom_urls visible at the class level
And a test for class/instance URL visibility
- Loading branch information
1 parent
283a31a
commit 61ac785
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class CustomUrlModel < RemoteModule::RemoteModel | ||
collection_url "collection" | ||
member_url "collection/:id" | ||
|
||
custom_urls :a_url => "custom", :format_url => "custom/:var", | ||
:method_url => "custom/:a_method" | ||
|
||
def id | ||
8 | ||
end | ||
|
||
def a_method | ||
10 | ||
end | ||
end | ||
|
||
describe "URLs" do | ||
it "should make visible urls at class and instance level" do | ||
CustomUrlModel.a_url.should == "custom" | ||
CustomUrlModel.collection_url.should == "collection" | ||
CustomUrlModel.member_url.should == "collection/:id" | ||
|
||
# NOTE that Class.member_url(params) won't work (it's the setter). | ||
CustomUrlModel.member_url.format(:id => 9).should == "collection/9" | ||
|
||
c = CustomUrlModel.new | ||
c.collection_url.should == "collection" | ||
c.member_url.should == "collection/8" | ||
c.a_url.should == "custom" | ||
|
||
CustomUrlModel.format_url.should == "custom/:var" | ||
c.format_url(:var => 3).should == "custom/3" | ||
c.method_url.should == "custom/10" | ||
end | ||
end |