ar_http_wrapper 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -1,3 +1,6 @@
1
1
  = ArHttpWrapper
2
2
 
3
- This project rocks and uses MIT-LICENSE.
3
+ = Tests
4
+
5
+ require ar_http_wrapper/spec_support
6
+ it_behaves_like "ActiveRecordApiWrapper"
@@ -0,0 +1,132 @@
1
+ shared_examples "ActiveRecordApiWrapper" do |klass,mountpoint,api_version|
2
+ subject {klass}
3
+ let(:mountpoint) {mountpoint}
4
+ let(:api_version) {nil}
5
+ def subject_name
6
+ subject.to_s.underscore
7
+ end
8
+ def api_version_path
9
+ api_version ? api_version+'/' : ''
10
+ end
11
+ def to_path(_path='')
12
+ "#{mountpoint}/#{api_version}#{subject_name}/#{_path}"
13
+ end
14
+
15
+ describe "GET new" do
16
+ before(:each) do
17
+ @id = "1"
18
+ @test_instance = {'id' => @id, "name" => "nom"}
19
+ subject.should_receive(:new).and_return(@test_instance)
20
+ end
21
+ it "builds instance" do
22
+ get "#{to_path("/new")}"
23
+ response.status.should == 200
24
+ end
25
+ it "returns instance" do
26
+ get "#{to_path("/new")}"
27
+ response.status.should == 200
28
+ JSON.parse(response.body).should == @test_instance
29
+ end
30
+ end
31
+
32
+ describe "POST create" do
33
+ before(:each) do
34
+ @id = "1"
35
+ @test_instance = {'id' => @id, "name" => "nom"}
36
+ subject.should_receive(:create).with(@test_instance).and_return(@test_instance)
37
+ end
38
+ it "creates instance" do
39
+ post "#{to_path}", subject.to_s.underscore.to_sym => @test_instance
40
+ response.status.should == 201
41
+ end
42
+ it "returns instance" do
43
+ post "#{to_path}", subject.to_s.underscore.to_sym => @test_instance
44
+ response.status.should == 201
45
+ JSON.parse(response.body).should == @test_instance
46
+ end
47
+ end
48
+
49
+ describe "PUT update" do
50
+ before(:each) do
51
+ @id = "1"
52
+ @test_instance = {'id' => @id, "name" => "nom"}
53
+ @updated_instance = {'id' => @id, 'name' => 'name'}
54
+ subject.should_receive(:find_by_id).with(@id).and_return(@test_instance)
55
+ @test_instance.should_receive(:update_attributes).with(@updated_instance).and_return(@updated_instance)
56
+ end
57
+ it "finds instance" do
58
+ put "#{to_path(@id)}", subject.to_s.underscore.to_sym => @updated_instance
59
+ response.status.should == 200
60
+ end
61
+ it "returns instance" do
62
+ put "#{to_path(@id)}", subject.to_s.underscore.to_sym => @updated_instance
63
+ response.status.should == 200
64
+ JSON.parse(response.body).should == @updated_instance
65
+ end
66
+ end
67
+
68
+ describe "GET show" do
69
+ before(:each) do
70
+ @id = "1"
71
+ @test_instance = {'id' => @id}
72
+ subject.should_receive(:find_by_id).with(@id).and_return(@test_instance)
73
+ end
74
+ it "finds instance" do
75
+ get "#{to_path(@id)}"
76
+ response.status.should == 200
77
+ end
78
+ it "returns instance" do
79
+ get "#{to_path(@id)}"
80
+ response.status.should == 200
81
+ JSON.parse(response.body).should == @test_instance
82
+ end
83
+ end
84
+
85
+ describe "DELETE destroy" do
86
+ before(:each) do
87
+ @id = "1"
88
+ @test_instance = {'id' => @id}
89
+ subject.should_receive(:find_by_id).with(@id).and_return(@test_instance)
90
+ @test_instance.should_receive(:try).with(:destroy).and_return(@test_instance)
91
+ end
92
+ it "destroys instance" do
93
+ delete "#{to_path(@id)}"
94
+ response.status.should == 200
95
+ end
96
+ it "returns instance" do
97
+ delete "#{to_path(@id)}"
98
+ response.status.should == 200
99
+ JSON.parse(response.body).should == @test_instance
100
+ end
101
+ end
102
+
103
+ describe "GET index " do
104
+ before(:each) do
105
+ @result = {"records" => "records"}
106
+ subject.stub(:find).and_return(@result)
107
+ end
108
+ it "returns records" do
109
+ get "#{to_path}"
110
+ response.status.should == 200
111
+ JSON.parse(response.body).should == @result
112
+ end
113
+ it "filters records by conditions" do
114
+ conditions = ["a=?","2"]
115
+ other_result = {"results" => "results"}
116
+ subject.unstub!(:find)
117
+ subject.should_receive(:find).with(:all, :conditions => conditions, :offset => nil, :limit => nil).and_return(other_result)
118
+ get "#{to_path}", :conditions => conditions
119
+ response.status.should == 200
120
+ JSON.parse(response.body).should == other_result
121
+ end
122
+ it "filters records by batch" do
123
+ offset,limit = "2","2"
124
+ other_result = {"results" => "results"}
125
+ subject.unstub!(:find)
126
+ subject.should_receive(:find).with(:all, :conditions => nil, :offset => offset, :limit => limit).and_return(other_result)
127
+ get "#{to_path}", :offset => offset, :limit => limit
128
+ response.status.should == 200
129
+ JSON.parse(response.body).should == other_result
130
+ end
131
+ end
132
+ end
@@ -1,3 +1,3 @@
1
1
  module ArHttpWrapper
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_http_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -183,6 +183,7 @@ files:
183
183
  - lib/ar_http_wrapper/active_record_api_wrapper.rb
184
184
  - lib/ar_http_wrapper/active_record_http_wrapper.rb
185
185
  - lib/ar_http_wrapper/engine.rb
186
+ - lib/ar_http_wrapper/spec_support.rb
186
187
  - lib/ar_http_wrapper/version.rb
187
188
  - lib/ar_http_wrapper.rb
188
189
  - lib/tasks/ar_http_wrapper_tasks.rake