Auto correct rubocop style issues
This commit is contained in:
parent
f260e607bf
commit
7e8c1d041d
39 changed files with 115 additions and 199 deletions
|
|
@ -12,6 +12,7 @@ describe Api::V1::OrderArticlesController, type: :controller do
|
|||
context "with param q[ordered]" do
|
||||
let(:order) { create(:order, article_count: 4) }
|
||||
let(:order_articles) { order.order_articles }
|
||||
|
||||
before do
|
||||
order_articles[0].update_attributes! quantity: 0, tolerance: 0, units_to_order: 0
|
||||
order_articles[1].update_attributes! quantity: 1, tolerance: 0, units_to_order: 0
|
||||
|
|
@ -42,6 +43,7 @@ describe Api::V1::OrderArticlesController, type: :controller do
|
|||
context "when ordered by user" do
|
||||
let(:user) { create(:user, :ordergroup) }
|
||||
let(:go) { create(:group_order, order: order, ordergroup: user.ordergroup) }
|
||||
|
||||
before do
|
||||
create(:group_order_article, group_order: go, order_article: order_articles[1], quantity: 1)
|
||||
create(:group_order_article, group_order: go, order_article: order_articles[2], tolerance: 0)
|
||||
|
|
|
|||
|
|
@ -53,13 +53,13 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
let!(:ft_2) { create :financial_transaction, ordergroup: user.ordergroup }
|
||||
let!(:ft_3) { create :financial_transaction, ordergroup: user.ordergroup }
|
||||
|
||||
let(:create_params) { { '_data' => { financial_transaction: { amount: 1, financial_transaction_type_id: ft_1.financial_transaction_type.id, note: 'note' } } } }
|
||||
|
||||
it { is_expected.to validate(:get, '/user/financial_transactions', 200, api_auth) }
|
||||
it { is_expected.to validate(:get, '/user/financial_transactions/{id}', 200, api_auth({ 'id' => ft_2.id })) }
|
||||
it { is_expected.to validate(:get, '/user/financial_transactions/{id}', 404, api_auth({ 'id' => other_ft_1.id })) }
|
||||
it { is_expected.to validate(:get, '/user/financial_transactions/{id}', 404, api_auth({ 'id' => FinancialTransaction.last.id + 1 })) }
|
||||
|
||||
let(:create_params) { { '_data' => { financial_transaction: { amount: 1, financial_transaction_type_id: ft_1.financial_transaction_type.id, note: 'note' } } } }
|
||||
|
||||
context 'without using self service' do
|
||||
it { is_expected.to validate(:post, '/user/financial_transactions', 403, api_auth(create_params)) }
|
||||
end
|
||||
|
|
@ -83,6 +83,7 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
|
||||
context 'without enough balance' do
|
||||
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
||||
|
||||
it { is_expected.to validate(:post, '/user/financial_transactions', 403, api_auth(create_params)) }
|
||||
end
|
||||
end
|
||||
|
|
@ -100,6 +101,7 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
let(:user_2) { create :user, :ordergroup }
|
||||
let(:group_order_2) { create(:group_order, order: order, ordergroup: user_2.ordergroup) }
|
||||
let!(:goa_2) { create :group_order_article, order_article: order.order_articles[0], group_order: group_order_2 }
|
||||
|
||||
before { group_order_2.update_price!; user_2.ordergroup.update_stats! }
|
||||
|
||||
context 'without ordergroup' do
|
||||
|
|
@ -109,8 +111,11 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
|
||||
context 'with ordergroup' do
|
||||
let(:user) { create :user, :ordergroup }
|
||||
let(:update_params) { { 'id' => goa.id, '_data' => { group_order_article: { quantity: goa.quantity + 1, tolerance: 0 } } } }
|
||||
let(:create_params) { { '_data' => { group_order_article: { order_article_id: order.order_articles[1].id, quantity: 1 } } } }
|
||||
let(:group_order) { create(:group_order, order: order, ordergroup: user.ordergroup) }
|
||||
let!(:goa) { create :group_order_article, order_article: order.order_articles[0], group_order: group_order }
|
||||
|
||||
before { group_order.update_price!; user.ordergroup.update_stats! }
|
||||
|
||||
it { is_expected.to validate(:get, '/user/group_order_articles', 200, api_auth) }
|
||||
|
|
@ -118,9 +123,6 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
it { is_expected.to validate(:get, '/user/group_order_articles/{id}', 404, api_auth({ 'id' => goa_2.id })) }
|
||||
it { is_expected.to validate(:get, '/user/group_order_articles/{id}', 404, api_auth({ 'id' => GroupOrderArticle.last.id + 1 })) }
|
||||
|
||||
let(:create_params) { { '_data' => { group_order_article: { order_article_id: order.order_articles[1].id, quantity: 1 } } } }
|
||||
let(:update_params) { { 'id' => goa.id, '_data' => { group_order_article: { quantity: goa.quantity + 1, tolerance: 0 } } } }
|
||||
|
||||
it { is_expected.to validate(:post, '/user/group_order_articles', 200, api_auth(create_params)) }
|
||||
it { is_expected.to validate(:patch, '/user/group_order_articles/{id}', 200, api_auth(update_params)) }
|
||||
it { is_expected.to validate(:delete, '/user/group_order_articles/{id}', 200, api_auth({ 'id' => goa.id })) }
|
||||
|
|
@ -149,6 +151,7 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
|
||||
context 'without enough balance' do
|
||||
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
||||
|
||||
it { is_expected.to validate(:post, '/user/group_order_articles', 403, api_auth(create_params)) }
|
||||
it { is_expected.to validate(:patch, '/user/group_order_articles/{id}', 403, api_auth(update_params)) }
|
||||
it { is_expected.to validate(:delete, '/user/group_order_articles/{id}', 200, api_auth({ 'id' => goa.id })) }
|
||||
|
|
@ -156,6 +159,7 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
|
||||
context 'without enough apple points' do
|
||||
before { allow_any_instance_of(Ordergroup).to receive(:not_enough_apples?).and_return(true) }
|
||||
|
||||
it { is_expected.to validate(:post, '/user/group_order_articles', 403, api_auth(create_params)) }
|
||||
it { is_expected.to validate(:patch, '/user/group_order_articles/{id}', 403, api_auth(update_params)) }
|
||||
it { is_expected.to validate(:delete, '/user/group_order_articles/{id}', 200, api_auth({ 'id' => goa.id })) }
|
||||
|
|
@ -198,6 +202,7 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
|
||||
context 'without role_finance' do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
it { is_expected.to validate(:get, '/financial_transactions', 403, api_auth) }
|
||||
it { is_expected.to validate(:get, '/financial_transactions/{id}', 403, api_auth({ 'id' => ft_2.id })) }
|
||||
end
|
||||
|
|
|
|||
|
|
@ -83,21 +83,25 @@ describe Api::V1::User::FinancialTransactionsController, type: :controller do
|
|||
|
||||
context "with existing financial transaction" do
|
||||
before { user.ordergroup.add_financial_transaction! 5000, 'for ordering', user, ftt3 }
|
||||
|
||||
include_examples "financial_transactions create/update success"
|
||||
end
|
||||
|
||||
context "with invalid financial transaction type" do
|
||||
let(:ft_params) { { amount: amount, financial_transaction_type_id: -1, note: note } }
|
||||
|
||||
include_examples "financial_transactions endpoint failure", 404
|
||||
end
|
||||
|
||||
context "without note" do
|
||||
let(:ft_params) { { amount: amount, financial_transaction_type_id: ftt1.id } }
|
||||
|
||||
include_examples "financial_transactions endpoint failure", 422
|
||||
end
|
||||
|
||||
context 'without enough balance' do
|
||||
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
||||
|
||||
include_examples "financial_transactions endpoint failure", 403
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ require 'spec_helper'
|
|||
describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
||||
include ApiOAuth
|
||||
let(:user) { create(:user, :ordergroup) }
|
||||
let(:json_goa) { json_response['group_order_article'] }
|
||||
let(:json_oa) { json_response['order_article'] }
|
||||
let(:api_scopes) { ['group_orders:user'] }
|
||||
|
||||
let(:order) { create(:order, article_count: 1) }
|
||||
|
|
@ -14,10 +16,8 @@ describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
|||
let(:user_other) { create(:user, :ordergroup) }
|
||||
let!(:go_other) { create(:group_order, order: order, ordergroup: user_other.ordergroup) }
|
||||
let!(:goa_other) { create(:group_order_article, group_order: go_other, order_article: oa_1, quantity: other_quantity, tolerance: other_tolerance) }
|
||||
before { go_other.update_price!; user_other.ordergroup.update_stats! }
|
||||
|
||||
let(:json_goa) { json_response['group_order_article'] }
|
||||
let(:json_oa) { json_response['order_article'] }
|
||||
before { go_other.update_price!; user_other.ordergroup.update_stats! }
|
||||
|
||||
shared_examples "group_order_articles endpoint success" do
|
||||
before { request }
|
||||
|
|
@ -95,47 +95,54 @@ describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
|||
|
||||
context "with an existing group_order" do
|
||||
let!(:go) { create(:group_order, order: order, ordergroup: user.ordergroup) }
|
||||
|
||||
include_examples "group_order_articles create/update success"
|
||||
end
|
||||
|
||||
context "with an existing group_order_article" do
|
||||
let!(:go) { create(:group_order, order: order, ordergroup: user.ordergroup) }
|
||||
let!(:goa) { create(:group_order_article, group_order: go, order_article: oa_1, quantity: 0, tolerance: 1) }
|
||||
|
||||
before { go.update_price!; user.ordergroup.update_stats! }
|
||||
|
||||
include_examples "group_order_articles endpoint failure", 422
|
||||
end
|
||||
|
||||
context "with invalid parameter values" do
|
||||
let(:goa_params) { { order_article_id: oa_1.id, quantity: -1, tolerance: new_tolerance } }
|
||||
|
||||
include_examples "group_order_articles endpoint failure", 422
|
||||
end
|
||||
|
||||
context 'with a closed order' do
|
||||
let(:order) { create(:order, article_count: 1, state: :finished) }
|
||||
|
||||
include_examples "group_order_articles endpoint failure", 404
|
||||
end
|
||||
|
||||
context 'without enough balance' do
|
||||
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
||||
|
||||
include_examples "group_order_articles endpoint failure", 403
|
||||
end
|
||||
|
||||
context 'without enough apple points' do
|
||||
before { allow_any_instance_of(Ordergroup).to receive(:not_enough_apples?).and_return(true) }
|
||||
|
||||
include_examples "group_order_articles endpoint failure", 403
|
||||
end
|
||||
end
|
||||
|
||||
describe "PATCH :update" do
|
||||
let(:new_quantity) { rand(2..10) }
|
||||
let(:goa_params) { { quantity: new_quantity, tolerance: new_tolerance } }
|
||||
let(:request) { patch :update, params: { id: goa.id, group_order_article: goa_params, foodcoop: 'f' } }
|
||||
let(:new_tolerance) { rand(2..10) }
|
||||
|
||||
let!(:go) { create(:group_order, order: order, ordergroup: user.ordergroup) }
|
||||
let!(:goa) { create(:group_order_article, group_order: go, order_article: oa_1, quantity: 1, tolerance: 0) }
|
||||
before { go.update_price!; user.ordergroup.update_stats! }
|
||||
|
||||
let(:goa_params) { { quantity: new_quantity, tolerance: new_tolerance } }
|
||||
let(:request) { patch :update, params: { id: goa.id, group_order_article: goa_params, foodcoop: 'f' } }
|
||||
before { go.update_price!; user.ordergroup.update_stats! }
|
||||
|
||||
context "happy flow" do
|
||||
include_examples "group_order_articles create/update success"
|
||||
|
|
@ -143,34 +150,38 @@ describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
|||
|
||||
context "with invalid parameter values" do
|
||||
let(:goa_params) { { order_article_id: oa_1.id, quantity: -1, tolerance: new_tolerance } }
|
||||
|
||||
include_examples "group_order_articles endpoint failure", 422
|
||||
end
|
||||
|
||||
context 'with a closed order' do
|
||||
let(:order) { create(:order, article_count: 1, state: :finished) }
|
||||
|
||||
include_examples "group_order_articles endpoint failure", 404
|
||||
end
|
||||
|
||||
context 'without enough balance' do
|
||||
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
||||
|
||||
include_examples "group_order_articles endpoint failure", 403
|
||||
end
|
||||
|
||||
context 'without enough apple points' do
|
||||
before { allow_any_instance_of(Ordergroup).to receive(:not_enough_apples?).and_return(true) }
|
||||
|
||||
include_examples "group_order_articles endpoint failure", 403
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE :destroy" do
|
||||
let(:new_quantity) { 0 }
|
||||
let(:request) { delete :destroy, params: { id: goa.id, foodcoop: 'f' } }
|
||||
let(:new_tolerance) { 0 }
|
||||
|
||||
let!(:go) { create(:group_order, order: order, ordergroup: user.ordergroup) }
|
||||
let!(:goa) { create(:group_order_article, group_order: go, order_article: oa_1) }
|
||||
before { go.update_price!; user.ordergroup.update_stats! }
|
||||
|
||||
let(:request) { delete :destroy, params: { id: goa.id, foodcoop: 'f' } }
|
||||
before { go.update_price!; user.ordergroup.update_stats! }
|
||||
|
||||
shared_examples "group_order_articles destroy success" do
|
||||
include_examples "group_order_articles endpoint success"
|
||||
|
|
@ -190,16 +201,19 @@ describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
|||
|
||||
context 'with a closed order' do
|
||||
let(:order) { create(:order, article_count: 1, state: :finished) }
|
||||
|
||||
include_examples "group_order_articles endpoint failure", 404
|
||||
end
|
||||
|
||||
context 'without enough balance' do
|
||||
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
||||
|
||||
include_examples "group_order_articles destroy success"
|
||||
end
|
||||
|
||||
context 'without enough apple points' do
|
||||
before { allow_any_instance_of(Ordergroup).to receive(:not_enough_apples?).and_return(true) }
|
||||
|
||||
include_examples "group_order_articles destroy success"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@ describe Api::V1::User::OrdergroupController, type: :controller do
|
|||
|
||||
describe "GET :financial_overview" do
|
||||
let(:order) { create(:order, article_count: 1) }
|
||||
let(:json_financial_overview) { json_response['financial_overview'] }
|
||||
let(:oa_1) { order.order_articles.first }
|
||||
|
||||
let!(:go) { create(:group_order, order: order, ordergroup: user.ordergroup) }
|
||||
let!(:goa) { create(:group_order_article, group_order: go, order_article: oa_1, quantity: 1, tolerance: 0) }
|
||||
before { go.update_price!; user.ordergroup.update_stats! }
|
||||
|
||||
let(:json_financial_overview) { json_response['financial_overview'] }
|
||||
before { go.update_price!; user.ordergroup.update_stats! }
|
||||
|
||||
before do
|
||||
og = user.ordergroup
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue