roar 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,59 +0,0 @@
1
- require 'test_helper'
2
- require 'roar/model'
3
-
4
- class AssertModelTest < MiniTest::Spec
5
- class Song
6
- include Roar::Model
7
- accessors :title
8
- end
9
-
10
- class Album
11
- include Roar::Model
12
- accessors :songs
13
- end
14
-
15
- class Play
16
- include Roar::Model
17
- accessors :song
18
- end
19
-
20
-
21
- describe "#assert_model" do
22
- before do
23
- @jerk = Song.new(:title => "Jerk")
24
- @sellout = Song.new(:title => "Sellout")
25
- @saleout = Song.new(:title => "Sellout")
26
- end
27
-
28
- it "compares to plain models" do
29
- assert_model @jerk, @jerk
30
- assert_model @sellout, @saleout
31
-
32
- assert_raises MiniTest::Assertion do
33
- assert_model @jerk, @sellout
34
- end
35
- end
36
-
37
- it "compares nested models" do
38
- @play = Play.new(:song => @sellout)
39
- @play_2 = Play.new(:song => @saleout)
40
- assert_model @play, @play_2
41
-
42
- assert_raises MiniTest::Assertion do
43
- assert_model @play, Play.new(:song => @jerk)
44
- end
45
- end
46
-
47
- it "compares nested models in collections" do
48
- @stay_asleep = Album.new(:songs => [@jerk, @sellout])
49
- @stay_asleep_ripped = Album.new(:songs => [@jerk, @saleout])
50
- assert_model @stay_asleep, @stay_asleep_ripped
51
-
52
- assert_raises MiniTest::Assertion do
53
- assert_model assert_model @stay_asleep, Album.new(:songs => [@jerk])
54
- end
55
- end
56
-
57
-
58
- end
59
- end
@@ -1,47 +0,0 @@
1
- require 'test_helper'
2
-
3
- class XmlHypermediaTest < MiniTest::Spec
4
- describe "Hypermedia API" do
5
- before do
6
- @c = Class.new(Roar::Representer::XML) do
7
- self.representation_name= :wuff
8
- representable_property :id
9
- link :self do "http://self" end
10
- link :next do "http://next/#{id}" end
11
- end
12
- @r = @c.new
13
- end
14
-
15
- it "responds to #links" do
16
- assert_equal nil, @r.links
17
- end
18
-
19
- it "computes links in #from_attributes" do
20
- @r = @c.from_attributes({"id" => 1})
21
- assert_equal 2, @r.links.size
22
- assert_equal({"rel"=>:self, "href"=>"http://self"}, @r.links.first.to_attributes)
23
- assert_equal({"rel"=>:next, "href"=>"http://next/1"}, @r.links.last.to_attributes)
24
- end
25
-
26
- it "extracts links from XML" do
27
- @r = @c.deserialize(%{
28
- <order>
29
- <link rel="self" href="http://self">
30
- </order>
31
- })
32
-
33
- assert_kind_of Roar::Representer::Feature::Hypermedia::LinkCollection, @r.links
34
- assert_equal 1, @r.links.size
35
- assert_equal({"rel"=>"self", "href"=>"http://self"}, @r.links.first.to_attributes)
36
- end
37
-
38
- it "renders <link> correctly in XML" do
39
- assert_xml_equal %{<wuff>
40
- <id>1</id>
41
- <link rel="self" href="http://self"/>
42
- <link rel="next" href="http://next/1"/>
43
- </wuff><expected />}, @c.from_attributes({"id" => 1}).serialize
44
- end
45
-
46
- end
47
- end