-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* renamed factories * added request spec for company#new * added rubocop-rspec * removed features * added create spec
- Loading branch information
1 parent
0546c7a
commit 3eb0a07
Showing
10 changed files
with
149 additions
and
2 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
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
File renamed without changes.
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
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,69 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe "Companies#create", type: :request do | ||
let (:user) { create(:user) } | ||
|
||
context "when authenticated" do | ||
before do | ||
sign_in user | ||
end | ||
|
||
context "when company is valid" do | ||
before do | ||
send_request(:post, company_path, params: { | ||
company: { | ||
name: "Test Company", | ||
address: "test address", | ||
business_phone: "Test phone", | ||
country: "India", | ||
timezone: "IN", | ||
base_currency: "Rs", | ||
standard_price: "1000", | ||
fiscal_year_end: "April", | ||
date_format: "DD/MM/YYYY" | ||
} | ||
}) | ||
end | ||
|
||
it "creates a new company" do | ||
expect(Company.count).to eq(1) | ||
end | ||
|
||
it "sets the company_id to current_user" do | ||
expect(user.company_id).to eq(Company.first.id) | ||
end | ||
|
||
it "redirects to root_path " do | ||
expect(response).to have_http_status(:redirect) | ||
end | ||
end | ||
context "when company is invalid" do | ||
before do | ||
send_request(:post, company_path, params: { | ||
company: { | ||
business_phone: "12345677", | ||
timezone: "", | ||
base_currency: "", | ||
standard_price: "", | ||
fiscal_year_end: "", | ||
date_format: "" | ||
} | ||
}) | ||
end | ||
|
||
it "creates a new company" do | ||
expect(response.body).to include("Company creation failed") | ||
end | ||
|
||
it "sets the company_id to current_user" do | ||
expect(Company.count).to eq(0) | ||
end | ||
|
||
it "redirects to root_path " do | ||
expect(response).to have_http_status(:unprocessable_entity) | ||
end | ||
end | ||
end | ||
end |
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,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe "Companies#new", type: :request do | ||
let (:user) { create(:user) } | ||
|
||
context "When authenticated" do | ||
before do | ||
sign_in user | ||
get new_company_path | ||
end | ||
|
||
it "is successful " do | ||
expect(response).to be_successful | ||
end | ||
|
||
it "renders Company#new page" do | ||
expect(response.body).to include("Setup Org") | ||
end | ||
end | ||
end |
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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
def send_request(request_type, url, headers: {}, params: {}) | ||
case request_type | ||
when :get | ||
get url, headers: headers, params: params | ||
when :post | ||
post url, headers: headers, params: params | ||
when :put | ||
put url, headers: headers, params: params | ||
when :delete | ||
delete url, headers: headers, params: params | ||
end | ||
end |