Commit b73d4419ea458a2824a35563bcd84d519b2a5516

Authored by Alex Denisov
1 parent 6b3ce96a

json_spec added. Create project via REST API fixed

@@ -117,6 +117,7 @@ group :test do @@ -117,6 +117,7 @@ group :test do
117 gem 'email_spec' 117 gem 'email_spec'
118 gem 'resque_spec' 118 gem 'resque_spec'
119 gem "webmock" 119 gem "webmock"
  120 + gem 'json_spec'
120 end 121 end
121 122
122 group :production do 123 group :production do
@@ -207,6 +207,9 @@ GEM @@ -207,6 +207,9 @@ GEM
207 jquery-rails 207 jquery-rails
208 railties (>= 3.1.0) 208 railties (>= 3.1.0)
209 json (1.7.5) 209 json (1.7.5)
  210 + json_spec (1.0.3)
  211 + multi_json (~> 1.0)
  212 + rspec (~> 2.0)
210 kaminari (0.14.0) 213 kaminari (0.14.0)
211 actionpack (>= 3.0.0) 214 actionpack (>= 3.0.0)
212 activesupport (>= 3.0.0) 215 activesupport (>= 3.0.0)
@@ -406,6 +409,7 @@ DEPENDENCIES @@ -406,6 +409,7 @@ DEPENDENCIES
406 httparty 409 httparty
407 jquery-rails (= 2.0.2) 410 jquery-rails (= 2.0.2)
408 jquery-ui-rails (= 0.5.0) 411 jquery-ui-rails (= 0.5.0)
  412 + json_spec
409 kaminari 413 kaminari
410 launchy 414 launchy
411 letter_opener 415 letter_opener
spec/factories.rb
@@ -11,6 +11,9 @@ module Factory @@ -11,6 +11,9 @@ module Factory
11 def self.new(type, *args) 11 def self.new(type, *args)
12 FactoryGirl.build(type, *args) 12 FactoryGirl.build(type, *args)
13 end 13 end
  14 + def self.attributes(type, *args)
  15 + FactoryGirl.attributes_for(type, *args)
  16 + end
14 end 17 end
15 18
16 FactoryGirl.define do 19 FactoryGirl.define do
spec/requests/api/projects_spec.rb
@@ -39,55 +39,19 @@ describe Gitlab::API do @@ -39,55 +39,19 @@ describe Gitlab::API do
39 }.should change{Project.count}.by(1) 39 }.should change{Project.count}.by(1)
40 end 40 end
41 it "should create new project" do 41 it "should create new project" do
42 - expect {  
43 - name = "foo"  
44 - path = "bar"  
45 - code = "bazz"  
46 - description = "fuu project"  
47 - default_branch = "default_branch"  
48 - issues_enabled = false  
49 - wall_enabled = false  
50 - merge_requests_enabled = false  
51 - wiki_enabled = false  
52 - post api("/projects", user), {  
53 - code: code,  
54 - path: path,  
55 - name: name,  
56 - description: description,  
57 - default_branch: default_branch,  
58 - issues_enabled: issues_enabled,  
59 - wall_enabled: wall_enabled,  
60 - merge_requests_enabled: merge_requests_enabled,  
61 - wiki_enabled: wiki_enabled  
62 - }  
63 - response.status.should == 201  
64 - json_response["name"].should == name  
65 - json_response["path"].should == path  
66 - json_response["code"].should == code  
67 - json_response["description"].should == description  
68 - json_response["default_branch"].should == default_branch  
69 - json_response["issues_enabled"].should == issues_enabled  
70 - json_response["wall_enabled"].should == wall_enabled  
71 - json_response["merge_requests_enabled"].should == merge_requests_enabled  
72 - json_response["wiki_enabled"].should == wiki_enabled  
73 - }.should change{Project.count}.by(1)  
74 - end  
75 - it "should create new projects within all parameters" do  
76 - expect {  
77 - name = "foo"  
78 - path = "bar"  
79 - code = "bazz"  
80 - post api("/projects", user), {  
81 - code: code,  
82 - path: path,  
83 - name: name  
84 - }  
85 - response.status.should == 201  
86 - json_response["name"].should == name  
87 - json_response["path"].should == path  
88 - json_response["code"].should == code  
89 - }.should change{Project.count}.by(1)  
90 - 42 + attributes = Factory.attributes(:project,
  43 + name: "foo",
  44 + path: "bar",
  45 + code: "bazz",
  46 + description: "foo project",
  47 + default_branch: "default_branch",
  48 + issues_enabled: false,
  49 + wall_enabled: false,
  50 + merge_requests_enabled: false,
  51 + wiki_enabled: false)
  52 + post api("/projects", user), attributes
  53 + response.status.should == 201
  54 + response.body.should be_json_eql(attributes.to_json).excluding("owner", "private")
91 end 55 end
92 it "should not create project without name" do 56 it "should not create project without name" do
93 expect { 57 expect {
spec/spec_helper.rb
@@ -28,6 +28,7 @@ RSpec.configure do |config| @@ -28,6 +28,7 @@ RSpec.configure do |config|
28 config.include LoginHelpers, type: :request 28 config.include LoginHelpers, type: :request
29 config.include GitoliteStub 29 config.include GitoliteStub
30 config.include FactoryGirl::Syntax::Methods 30 config.include FactoryGirl::Syntax::Methods
  31 + config.include JsonSpec::Helpers
31 32
32 # If you're not using ActiveRecord, or you'd prefer not to run each of your 33 # If you're not using ActiveRecord, or you'd prefer not to run each of your
33 # examples within a transaction, remove the following line or assign false 34 # examples within a transaction, remove the following line or assign false