From b73d4419ea458a2824a35563bcd84d519b2a5516 Mon Sep 17 00:00:00 2001 From: Alex Denisov <1101.debian@gmail.com> Date: Tue, 4 Sep 2012 09:38:48 +0300 Subject: [PATCH] json_spec added. Create project via REST API fixed --- Gemfile | 1 + Gemfile.lock | 4 ++ spec/factories.rb | 3 ++ spec/requests/api/projects_spec.rb | 62 +++++++----------------------- spec/spec_helper.rb | 1 + 5 files changed, 22 insertions(+), 49 deletions(-) diff --git a/Gemfile b/Gemfile index b0724fadf5b..33f9cf4c1ea 100644 --- a/Gemfile +++ b/Gemfile @@ -117,6 +117,7 @@ group :test do gem 'email_spec' gem 'resque_spec' gem "webmock" + gem 'json_spec' end group :production do diff --git a/Gemfile.lock b/Gemfile.lock index 7ec37f59dfc..ae85a43a7bf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -207,6 +207,9 @@ GEM jquery-rails railties (>= 3.1.0) json (1.7.5) + json_spec (1.0.3) + multi_json (~> 1.0) + rspec (~> 2.0) kaminari (0.14.0) actionpack (>= 3.0.0) activesupport (>= 3.0.0) @@ -406,6 +409,7 @@ DEPENDENCIES httparty jquery-rails (= 2.0.2) jquery-ui-rails (= 0.5.0) + json_spec kaminari launchy letter_opener diff --git a/spec/factories.rb b/spec/factories.rb index 2e4acf39461..95c919fd915 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -11,6 +11,9 @@ module Factory def self.new(type, *args) FactoryGirl.build(type, *args) end + def self.attributes(type, *args) + FactoryGirl.attributes_for(type, *args) + end end FactoryGirl.define do diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index cdab2657012..43c44974bb0 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -39,55 +39,19 @@ describe Gitlab::API do }.should change{Project.count}.by(1) end it "should create new project" do - expect { - name = "foo" - path = "bar" - code = "bazz" - description = "fuu project" - default_branch = "default_branch" - issues_enabled = false - wall_enabled = false - merge_requests_enabled = false - wiki_enabled = false - post api("/projects", user), { - code: code, - path: path, - name: name, - description: description, - default_branch: default_branch, - issues_enabled: issues_enabled, - wall_enabled: wall_enabled, - merge_requests_enabled: merge_requests_enabled, - wiki_enabled: wiki_enabled - } - response.status.should == 201 - json_response["name"].should == name - json_response["path"].should == path - json_response["code"].should == code - json_response["description"].should == description - json_response["default_branch"].should == default_branch - json_response["issues_enabled"].should == issues_enabled - json_response["wall_enabled"].should == wall_enabled - json_response["merge_requests_enabled"].should == merge_requests_enabled - json_response["wiki_enabled"].should == wiki_enabled - }.should change{Project.count}.by(1) - end - it "should create new projects within all parameters" do - expect { - name = "foo" - path = "bar" - code = "bazz" - post api("/projects", user), { - code: code, - path: path, - name: name - } - response.status.should == 201 - json_response["name"].should == name - json_response["path"].should == path - json_response["code"].should == code - }.should change{Project.count}.by(1) - + attributes = Factory.attributes(:project, + name: "foo", + path: "bar", + code: "bazz", + description: "foo project", + default_branch: "default_branch", + issues_enabled: false, + wall_enabled: false, + merge_requests_enabled: false, + wiki_enabled: false) + post api("/projects", user), attributes + response.status.should == 201 + response.body.should be_json_eql(attributes.to_json).excluding("owner", "private") end it "should not create project without name" do expect { diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d381b3f1e2e..30a213bac18 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,6 +28,7 @@ RSpec.configure do |config| config.include LoginHelpers, type: :request config.include GitoliteStub config.include FactoryGirl::Syntax::Methods + config.include JsonSpec::Helpers # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false -- GitLab