Run rubocop --fix-layout and remove encoding comments
This commit is contained in:
parent
fa63e6e81d
commit
ea2862fdef
283 changed files with 1164 additions and 1969 deletions
|
|
@ -6,7 +6,7 @@ describe Api::V1::OrderArticlesController, type: :controller do
|
|||
let(:api_scopes) { ['orders:read'] }
|
||||
|
||||
let(:json_order_articles) { json_response['order_articles'] }
|
||||
let(:json_order_article_ids) { json_order_articles.map {|joa| joa["id"] } }
|
||||
let(:json_order_article_ids) { json_order_articles.map { |joa| joa["id"] } }
|
||||
|
||||
describe "GET :index" do
|
||||
context "with param q[ordered]" do
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
|
||||
context 'without ordergroup' do
|
||||
it { is_expected.to validate(:get, '/user/financial_transactions', 403, api_auth) }
|
||||
it { is_expected.to validate(:get, '/user/financial_transactions/{id}', 403, api_auth({'id' => other_ft_1.id})) }
|
||||
it { is_expected.to validate(:get, '/user/financial_transactions/{id}', 403, api_auth({ 'id' => other_ft_1.id })) }
|
||||
end
|
||||
|
||||
context 'with ordergroup' do
|
||||
|
|
@ -54,11 +54,11 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
let!(:ft_3) { create :financial_transaction, ordergroup: user.ordergroup }
|
||||
|
||||
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})) }
|
||||
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'}}} }
|
||||
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)) }
|
||||
|
|
@ -70,13 +70,13 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
it { is_expected.to validate(:post, '/user/financial_transactions', 200, api_auth(create_params)) }
|
||||
|
||||
context 'with invalid financial transaction type' do
|
||||
let(:create_params) { {'_data' => {financial_transaction: {amount: 1, financial_transaction_type_id: -1, note: 'note'}}} }
|
||||
let(:create_params) { { '_data' => { financial_transaction: { amount: 1, financial_transaction_type_id: -1, note: 'note' } } } }
|
||||
|
||||
it { is_expected.to validate(:post, '/user/financial_transactions', 404, api_auth(create_params)) }
|
||||
end
|
||||
|
||||
context 'without note' do
|
||||
let(:create_params) { {'_data' => {financial_transaction: {amount: 1, financial_transaction_type_id: ft_1.financial_transaction_type.id}}} }
|
||||
let(:create_params) { { '_data' => { financial_transaction: { amount: 1, financial_transaction_type_id: ft_1.financial_transaction_type.id } } } }
|
||||
|
||||
it { is_expected.to validate(:post, '/user/financial_transactions', 422, api_auth(create_params)) }
|
||||
end
|
||||
|
|
@ -88,8 +88,8 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
end
|
||||
|
||||
it_handles_invalid_token_and_scope(:get, '/user/financial_transactions')
|
||||
it_handles_invalid_token_and_scope(:post, '/user/financial_transactions', ->{ api_auth(create_params) })
|
||||
it_handles_invalid_token_and_scope(:get, '/user/financial_transactions/{id}', ->{ api_auth('id' => ft_2.id) })
|
||||
it_handles_invalid_token_and_scope(:post, '/user/financial_transactions', -> { api_auth(create_params) })
|
||||
it_handles_invalid_token_and_scope(:get, '/user/financial_transactions/{id}', -> { api_auth('id' => ft_2.id) })
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -104,7 +104,7 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
|
||||
context 'without ordergroup' do
|
||||
it { is_expected.to validate(:get, '/user/group_order_articles', 403, api_auth) }
|
||||
it { is_expected.to validate(:get, '/user/group_order_articles/{id}', 403, api_auth({'id' => goa_2.id})) }
|
||||
it { is_expected.to validate(:get, '/user/group_order_articles/{id}', 403, api_auth({ 'id' => goa_2.id })) }
|
||||
end
|
||||
|
||||
context 'with ordergroup' do
|
||||
|
|
@ -114,26 +114,26 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
before { group_order.update_price!; user.ordergroup.update_stats! }
|
||||
|
||||
it { is_expected.to validate(:get, '/user/group_order_articles', 200, api_auth) }
|
||||
it { is_expected.to validate(:get, '/user/group_order_articles/{id}', 200, api_auth({'id' => goa.id})) }
|
||||
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})) }
|
||||
it { is_expected.to validate(:get, '/user/group_order_articles/{id}', 200, api_auth({ 'id' => goa.id })) }
|
||||
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}}} }
|
||||
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})) }
|
||||
it { is_expected.to validate(:delete, '/user/group_order_articles/{id}', 200, api_auth({ 'id' => goa.id })) }
|
||||
|
||||
context 'with an existing group_order_article' do
|
||||
let(:create_params) { {'_data' => {group_order_article: {order_article_id: order.order_articles[0].id, quantity: 1}}} }
|
||||
let(:create_params) { { '_data' => { group_order_article: { order_article_id: order.order_articles[0].id, quantity: 1 } } } }
|
||||
|
||||
it { is_expected.to validate(:post, '/user/group_order_articles', 422, api_auth(create_params)) }
|
||||
end
|
||||
|
||||
context 'with invalid parameter values' do
|
||||
let(:create_params) { {'_data' => {group_order_article: {order_article_id: order.order_articles[0].id, quantity: -1}}} }
|
||||
let(:update_params) { {'id' => goa.id, '_data' => {group_order_article: {quantity: -1, tolerance: 0}}} }
|
||||
let(:create_params) { { '_data' => { group_order_article: { order_article_id: order.order_articles[0].id, quantity: -1 } } } }
|
||||
let(:update_params) { { 'id' => goa.id, '_data' => { group_order_article: { quantity: -1, tolerance: 0 } } } }
|
||||
|
||||
it { is_expected.to validate(:post, '/user/group_order_articles', 422, api_auth(create_params)) }
|
||||
it { is_expected.to validate(:patch, '/user/group_order_articles/{id}', 422, api_auth(update_params)) }
|
||||
|
|
@ -144,28 +144,28 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
|
||||
it { is_expected.to validate(:post, '/user/group_order_articles', 404, api_auth(create_params)) }
|
||||
it { is_expected.to validate(:patch, '/user/group_order_articles/{id}', 404, api_auth(update_params)) }
|
||||
it { is_expected.to validate(:delete, '/user/group_order_articles/{id}', 404, api_auth({'id' => goa.id})) }
|
||||
it { is_expected.to validate(:delete, '/user/group_order_articles/{id}', 404, api_auth({ 'id' => goa.id })) }
|
||||
end
|
||||
|
||||
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})) }
|
||||
it { is_expected.to validate(:delete, '/user/group_order_articles/{id}', 200, api_auth({ 'id' => goa.id })) }
|
||||
end
|
||||
|
||||
context 'without enough apple points' do
|
||||
before { allow_any_instance_of(Ordergroup).to receive(:not_enough_apples?).and_return(true) }
|
||||
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})) }
|
||||
it { is_expected.to validate(:delete, '/user/group_order_articles/{id}', 200, api_auth({ 'id' => goa.id })) }
|
||||
end
|
||||
|
||||
it_handles_invalid_token_and_scope(:get, '/user/group_order_articles')
|
||||
it_handles_invalid_token_and_scope(:post, '/user/group_order_articles', ->{ api_auth(create_params) })
|
||||
it_handles_invalid_token_and_scope(:get, '/user/group_order_articles/{id}', ->{ api_auth({'id' => goa.id}) })
|
||||
it_handles_invalid_token_and_scope(:patch, '/user/group_order_articles/{id}', ->{ api_auth(update_params) })
|
||||
it_handles_invalid_token_and_scope(:delete, '/user/group_order_articles/{id}', ->{ api_auth({'id' => goa.id}) })
|
||||
it_handles_invalid_token_and_scope(:post, '/user/group_order_articles', -> { api_auth(create_params) })
|
||||
it_handles_invalid_token_and_scope(:get, '/user/group_order_articles/{id}', -> { api_auth({ 'id' => goa.id }) })
|
||||
it_handles_invalid_token_and_scope(:patch, '/user/group_order_articles/{id}', -> { api_auth(update_params) })
|
||||
it_handles_invalid_token_and_scope(:delete, '/user/group_order_articles/{id}', -> { api_auth({ 'id' => goa.id }) })
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -193,17 +193,17 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
let!(:ft_2) { create :financial_transaction, ordergroup: other_user.ordergroup }
|
||||
|
||||
it { is_expected.to validate(:get, '/financial_transactions', 200, api_auth) }
|
||||
it { is_expected.to validate(:get, '/financial_transactions/{id}', 200, api_auth({'id' => ft_2.id})) }
|
||||
it { is_expected.to validate(:get, '/financial_transactions/{id}', 404, api_auth({'id' => FinancialTransaction.last.id + 1})) }
|
||||
it { is_expected.to validate(:get, '/financial_transactions/{id}', 200, api_auth({ 'id' => ft_2.id })) }
|
||||
it { is_expected.to validate(:get, '/financial_transactions/{id}', 404, api_auth({ 'id' => FinancialTransaction.last.id + 1 })) }
|
||||
|
||||
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})) }
|
||||
it { is_expected.to validate(:get, '/financial_transactions/{id}', 403, api_auth({ 'id' => ft_2.id })) }
|
||||
end
|
||||
|
||||
it_handles_invalid_token_and_scope(:get, '/financial_transactions')
|
||||
it_handles_invalid_token_and_scope(:get, '/financial_transactions/{id}', ->{ api_auth({'id' => ft_2.id}) })
|
||||
it_handles_invalid_token_and_scope(:get, '/financial_transactions/{id}', -> { api_auth({ 'id' => ft_2.id }) })
|
||||
end
|
||||
|
||||
context 'financial_transaction_classes' do
|
||||
|
|
@ -211,11 +211,11 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
let!(:cla_2) { create :financial_transaction_class }
|
||||
|
||||
it { is_expected.to validate(:get, '/financial_transaction_classes', 200, api_auth) }
|
||||
it { is_expected.to validate(:get, '/financial_transaction_classes/{id}', 200, api_auth({'id' => cla_2.id})) }
|
||||
it { is_expected.to validate(:get, '/financial_transaction_classes/{id}', 404, api_auth({'id' => cla_2.id + 1})) }
|
||||
it { is_expected.to validate(:get, '/financial_transaction_classes/{id}', 200, api_auth({ 'id' => cla_2.id })) }
|
||||
it { is_expected.to validate(:get, '/financial_transaction_classes/{id}', 404, api_auth({ 'id' => cla_2.id + 1 })) }
|
||||
|
||||
it_handles_invalid_token(:get, '/financial_transaction_classes')
|
||||
it_handles_invalid_token(:get, '/financial_transaction_classes/{id}', ->{ api_auth({'id' => cla_1.id }) })
|
||||
it_handles_invalid_token(:get, '/financial_transaction_classes/{id}', -> { api_auth({ 'id' => cla_1.id }) })
|
||||
end
|
||||
|
||||
context 'financial_transaction_types' do
|
||||
|
|
@ -223,11 +223,11 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
let!(:tpy_2) { create :financial_transaction_type }
|
||||
|
||||
it { is_expected.to validate(:get, '/financial_transaction_types', 200, api_auth) }
|
||||
it { is_expected.to validate(:get, '/financial_transaction_types/{id}', 200, api_auth({'id' => tpy_2.id})) }
|
||||
it { is_expected.to validate(:get, '/financial_transaction_types/{id}', 404, api_auth({'id' => tpy_2.id + 1})) }
|
||||
it { is_expected.to validate(:get, '/financial_transaction_types/{id}', 200, api_auth({ 'id' => tpy_2.id })) }
|
||||
it { is_expected.to validate(:get, '/financial_transaction_types/{id}', 404, api_auth({ 'id' => tpy_2.id + 1 })) }
|
||||
|
||||
it_handles_invalid_token(:get, '/financial_transaction_types')
|
||||
it_handles_invalid_token(:get, '/financial_transaction_types/{id}', ->{ api_auth({'id' => tpy_1.id }) })
|
||||
it_handles_invalid_token(:get, '/financial_transaction_types/{id}', -> { api_auth({ 'id' => tpy_1.id }) })
|
||||
end
|
||||
|
||||
context 'orders' do
|
||||
|
|
@ -235,11 +235,11 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
let!(:order) { create :order }
|
||||
|
||||
it { is_expected.to validate(:get, '/orders', 200, api_auth) }
|
||||
it { is_expected.to validate(:get, '/orders/{id}', 200, api_auth({'id' => order.id})) }
|
||||
it { is_expected.to validate(:get, '/orders/{id}', 404, api_auth({'id' => Order.last.id + 1})) }
|
||||
it { is_expected.to validate(:get, '/orders/{id}', 200, api_auth({ 'id' => order.id })) }
|
||||
it { is_expected.to validate(:get, '/orders/{id}', 404, api_auth({ 'id' => Order.last.id + 1 })) }
|
||||
|
||||
it_handles_invalid_token_and_scope(:get, '/orders')
|
||||
it_handles_invalid_token_and_scope(:get, '/orders/{id}', ->{ api_auth({'id' => order.id}) })
|
||||
it_handles_invalid_token_and_scope(:get, '/orders/{id}', -> { api_auth({ 'id' => order.id }) })
|
||||
end
|
||||
|
||||
context 'order_articles' do
|
||||
|
|
@ -249,12 +249,12 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
let!(:stock_order_article) { create(:stock_order, article_ids: [stock_article.id]).order_articles.first }
|
||||
|
||||
it { is_expected.to validate(:get, '/order_articles', 200, api_auth) }
|
||||
it { is_expected.to validate(:get, '/order_articles/{id}', 200, api_auth({'id' => order_article.id})) }
|
||||
it { is_expected.to validate(:get, '/order_articles/{id}', 200, api_auth({'id' => stock_order_article.id})) }
|
||||
it { is_expected.to validate(:get, '/order_articles/{id}', 404, api_auth({'id' => Article.last.id + 1})) }
|
||||
it { is_expected.to validate(:get, '/order_articles/{id}', 200, api_auth({ 'id' => order_article.id })) }
|
||||
it { is_expected.to validate(:get, '/order_articles/{id}', 200, api_auth({ 'id' => stock_order_article.id })) }
|
||||
it { is_expected.to validate(:get, '/order_articles/{id}', 404, api_auth({ 'id' => Article.last.id + 1 })) }
|
||||
|
||||
it_handles_invalid_token_and_scope(:get, '/order_articles')
|
||||
it_handles_invalid_token_and_scope(:get, '/order_articles/{id}', ->{ api_auth({'id' => order_article.id}) })
|
||||
it_handles_invalid_token_and_scope(:get, '/order_articles/{id}', -> { api_auth({ 'id' => order_article.id }) })
|
||||
end
|
||||
|
||||
context 'article_categories' do
|
||||
|
|
@ -262,11 +262,11 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
let!(:cat_2) { create :article_category }
|
||||
|
||||
it { is_expected.to validate(:get, '/article_categories', 200, api_auth) }
|
||||
it { is_expected.to validate(:get, '/article_categories/{id}', 200, api_auth({'id' => cat_2.id})) }
|
||||
it { is_expected.to validate(:get, '/article_categories/{id}', 404, api_auth({'id' => cat_2.id + 1})) }
|
||||
it { is_expected.to validate(:get, '/article_categories/{id}', 200, api_auth({ 'id' => cat_2.id })) }
|
||||
it { is_expected.to validate(:get, '/article_categories/{id}', 404, api_auth({ 'id' => cat_2.id + 1 })) }
|
||||
|
||||
it_handles_invalid_token(:get, '/article_categories')
|
||||
it_handles_invalid_token(:get, '/article_categories/{id}', ->{ api_auth({'id' => cat_1.id }) })
|
||||
it_handles_invalid_token(:get, '/article_categories/{id}', -> { api_auth({ 'id' => cat_1.id }) })
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ describe Api::V1::User::FinancialTransactionsController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
shared_examples "financial_transactions endpoint failure" do |status|
|
||||
it "returns status #{status}" do
|
||||
request
|
||||
|
|
@ -67,7 +66,6 @@ describe Api::V1::User::FinancialTransactionsController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
describe "POST :create" do
|
||||
let(:ft_params) { { amount: amount, financial_transaction_type_id: ftt1.id, note: note } }
|
||||
let(:request) { post :create, params: { financial_transaction: ft_params, foodcoop: 'f' } }
|
||||
|
|
|
|||
|
|
@ -12,14 +12,13 @@ describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
|||
let(:other_quantity) { rand(1..10) }
|
||||
let(:other_tolerance) { rand(1..10) }
|
||||
let(:user_other) { create(:user, :ordergroup) }
|
||||
let!(:go_other) { create(:group_order, order: order, ordergroup: user_other.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'] }
|
||||
|
||||
|
||||
shared_examples "group_order_articles endpoint success" do
|
||||
before { request }
|
||||
|
||||
|
|
@ -38,8 +37,8 @@ describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
|||
expect {
|
||||
request
|
||||
go = user.ordergroup.group_orders.where(order: order).last
|
||||
}.to change { go&.updated_by }.to(user)
|
||||
.and change { go&.price }
|
||||
}.to change { go&.updated_by }.to(user)
|
||||
.and change { go&.price }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -61,7 +60,6 @@ describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
shared_examples "group_order_articles endpoint failure" do |status|
|
||||
it "returns status #{status}" do
|
||||
request
|
||||
|
|
@ -78,13 +76,12 @@ describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
|||
it "does not change the group_order_article" do
|
||||
expect { request }.to_not change {
|
||||
goa = GroupOrderArticle.joins(:group_order)
|
||||
.where(order_article_id: oa_1.id, group_orders: { ordergroup: user.ordergroup }).last
|
||||
.where(order_article_id: oa_1.id, group_orders: { ordergroup: user.ordergroup }).last
|
||||
goa&.attributes
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "POST :create" do
|
||||
let(:new_quantity) { rand(1..10) }
|
||||
let(:new_tolerance) { rand(1..10) }
|
||||
|
|
@ -109,7 +106,7 @@ describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
|||
end
|
||||
|
||||
context "with invalid parameter values" do
|
||||
let(:goa_params) { { order_article_id: oa_1.id, quantity: -1, tolerance: new_tolerance} }
|
||||
let(:goa_params) { { order_article_id: oa_1.id, quantity: -1, tolerance: new_tolerance } }
|
||||
include_examples "group_order_articles endpoint failure", 422
|
||||
end
|
||||
|
||||
|
|
@ -124,7 +121,7 @@ describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
|||
end
|
||||
|
||||
context 'without enough apple points' do
|
||||
before { allow_any_instance_of(Ordergroup).to receive(:not_enough_apples?).and_return(true) }
|
||||
before { allow_any_instance_of(Ordergroup).to receive(:not_enough_apples?).and_return(true) }
|
||||
include_examples "group_order_articles endpoint failure", 403
|
||||
end
|
||||
end
|
||||
|
|
@ -145,7 +142,7 @@ describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
|||
end
|
||||
|
||||
context "with invalid parameter values" do
|
||||
let(:goa_params) { { order_article_id: oa_1.id, quantity: -1, tolerance: new_tolerance} }
|
||||
let(:goa_params) { { order_article_id: oa_1.id, quantity: -1, tolerance: new_tolerance } }
|
||||
include_examples "group_order_articles endpoint failure", 422
|
||||
end
|
||||
|
||||
|
|
@ -160,7 +157,7 @@ describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
|||
end
|
||||
|
||||
context 'without enough apple points' do
|
||||
before { allow_any_instance_of(Ordergroup).to receive(:not_enough_apples?).and_return(true) }
|
||||
before { allow_any_instance_of(Ordergroup).to receive(:not_enough_apples?).and_return(true) }
|
||||
include_examples "group_order_articles endpoint failure", 403
|
||||
end
|
||||
end
|
||||
|
|
@ -175,7 +172,6 @@ describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
|||
|
||||
let(:request) { delete :destroy, params: { id: goa.id, foodcoop: 'f' } }
|
||||
|
||||
|
||||
shared_examples "group_order_articles destroy success" do
|
||||
include_examples "group_order_articles endpoint success"
|
||||
|
||||
|
|
@ -188,7 +184,6 @@ describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
context "happy flow" do
|
||||
include_examples "group_order_articles destroy success"
|
||||
end
|
||||
|
|
@ -204,7 +199,7 @@ describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
|||
end
|
||||
|
||||
context 'without enough apple points' do
|
||||
before { allow_any_instance_of(Ordergroup).to receive(:not_enough_apples?).and_return(true) }
|
||||
before { allow_any_instance_of(Ordergroup).to receive(:not_enough_apples?).and_return(true) }
|
||||
include_examples "group_order_articles destroy success"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ describe Api::V1::User::OrdergroupController, type: :controller do
|
|||
expect(json_financial_overview['account_balance']).to eq 444
|
||||
expect(json_financial_overview['available_funds']).to eq 444 - go.price
|
||||
|
||||
ftcs = Hash[ json_financial_overview['financial_transaction_class_sums'].map { |x| [x['id'], x] } ]
|
||||
ftcs = Hash[json_financial_overview['financial_transaction_class_sums'].map { |x| [x['id'], x] }]
|
||||
|
||||
ftcs1 = ftcs[ftc1.id]
|
||||
expect(ftcs1['name']).to eq ftc1.name
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
require 'factory_bot'
|
||||
|
||||
FactoryBot.define do
|
||||
|
||||
factory :_article do
|
||||
unit { Faker::Unit.unit }
|
||||
price { rand(0.1..26.0).round(2) }
|
||||
|
|
@ -32,5 +31,4 @@ FactoryBot.define do
|
|||
factory :article_category do
|
||||
sequence(:name) { |n| Faker::Lorem.characters(number: rand(2..12)) + " ##{n}" }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
require 'factory_bot'
|
||||
|
||||
FactoryBot.define do
|
||||
|
||||
factory :bank_account do
|
||||
name { Faker::Bank.name }
|
||||
iban { Faker::Bank.iban }
|
||||
|
|
@ -11,5 +10,4 @@ FactoryBot.define do
|
|||
date { Faker::Date.backward(days: 14) }
|
||||
text { Faker::Lorem.sentence }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ require 'factory_bot'
|
|||
require 'doorkeeper'
|
||||
|
||||
FactoryBot.define do
|
||||
|
||||
factory :oauth2_application, class: Doorkeeper::Application do
|
||||
name { Faker::App.name }
|
||||
redirect_uri { 'https://example.com:1234/app' }
|
||||
|
|
@ -11,5 +10,4 @@ FactoryBot.define do
|
|||
factory :oauth2_access_token, class: Doorkeeper::AccessToken do
|
||||
application factory: :oauth2_application
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
require 'factory_bot'
|
||||
|
||||
FactoryBot.define do
|
||||
|
||||
factory :financial_transaction_class do
|
||||
sequence(:name) { |n| Faker::Lorem.characters(number: rand(2..12)) + " ##{n}" }
|
||||
end
|
||||
|
|
@ -10,5 +9,4 @@ FactoryBot.define do
|
|||
financial_transaction_class
|
||||
sequence(:name) { |n| Faker::Lorem.words(number: rand(2..4)).join(' ') + " ##{n}" }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
require 'factory_bot'
|
||||
|
||||
FactoryBot.define do
|
||||
|
||||
# requires order
|
||||
factory :group_order do
|
||||
ordergroup { create(:user, groups: [FactoryBot.create(:ordergroup)]).ordergroup }
|
||||
updated_by { create :user }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
require 'factory_bot'
|
||||
|
||||
FactoryBot.define do
|
||||
|
||||
# requires order_article
|
||||
factory :group_order_article do
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
require 'factory_bot'
|
||||
|
||||
FactoryBot.define do
|
||||
|
||||
# requires order_article
|
||||
factory :group_order_article_quantity do
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
require 'factory_bot'
|
||||
|
||||
FactoryBot.define do
|
||||
|
||||
factory :invoice do
|
||||
supplier
|
||||
number { rand(1..99999) }
|
||||
|
|
@ -12,5 +11,4 @@ FactoryBot.define do
|
|||
invoice.supplier.reload
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
require 'factory_bot'
|
||||
|
||||
FactoryBot.define do
|
||||
|
||||
factory :order do
|
||||
starts { Time.now }
|
||||
supplier { create :supplier, article_count: (article_count.nil? ? true : article_count) }
|
||||
|
|
@ -25,5 +24,4 @@ FactoryBot.define do
|
|||
order.reload
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
require 'factory_bot'
|
||||
|
||||
FactoryBot.define do
|
||||
|
||||
factory :supplier do
|
||||
name { Faker::Company.name.truncate(30) }
|
||||
phone { Faker::PhoneNumber.phone_number }
|
||||
|
|
@ -14,6 +13,7 @@ FactoryBot.define do
|
|||
before :create do |supplier, evaluator|
|
||||
next if supplier.class == SharedSupplier
|
||||
next if supplier.supplier_category_id?
|
||||
|
||||
supplier.supplier_category = create :supplier_category
|
||||
end
|
||||
|
||||
|
|
@ -30,5 +30,4 @@ FactoryBot.define do
|
|||
sequence(:name) { |n| Faker::Lorem.characters(number: rand(2..12)) + " ##{n}" }
|
||||
financial_transaction_class
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
require 'factory_bot'
|
||||
|
||||
FactoryBot.define do
|
||||
|
||||
factory :user do
|
||||
sequence(:nick) { |n| "user#{n}"}
|
||||
sequence(:nick) { |n| "user#{n}" }
|
||||
first_name { Faker::Name.first_name }
|
||||
email { Faker::Internet.email }
|
||||
password { new_random_password }
|
||||
|
|
@ -32,7 +31,7 @@ FactoryBot.define do
|
|||
end
|
||||
|
||||
factory :group do
|
||||
sequence(:name) {|n| "Group ##{n}"}
|
||||
sequence(:name) { |n| "Group ##{n}" }
|
||||
|
||||
factory :workgroup do
|
||||
type { '' }
|
||||
|
|
@ -40,11 +39,10 @@ FactoryBot.define do
|
|||
|
||||
factory :ordergroup do
|
||||
type { 'Ordergroup' }
|
||||
sequence(:name) {|n| "Order group ##{n}"}
|
||||
sequence(:name) { |n| "Order group ##{n}" }
|
||||
# workaround to avoid needing to save the ordergroup
|
||||
# avoids e.g. error after logging in related to applebar
|
||||
after :create do |group| Ordergroup.find(group.id).update_stats! end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,6 +7,6 @@ Dir.glob('config/locales/??{-*,}.yml').each do |locale_file|
|
|||
# We're currently allowing both German and English as source language
|
||||
# besides, we're using localeapp, so that it's ok if pull requests
|
||||
# don't have this - a localapp pull will fix that right away.
|
||||
#it { expect(locale_file).to be_a_subset_of 'config/locales/en.yml' }
|
||||
# it { expect(locale_file).to be_a_subset_of 'config/locales/en.yml' }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
# encoding: utf-8
|
||||
require_relative '../spec_helper'
|
||||
|
||||
feature ArticlesController do
|
||||
let(:user) { create :user, groups:[create(:workgroup, role_article_meta: true)] }
|
||||
let(:user) { create :user, groups: [create(:workgroup, role_article_meta: true)] }
|
||||
let (:supplier) { create :supplier }
|
||||
let!(:article_category) { create :article_category }
|
||||
before { login user }
|
||||
|
|
@ -28,7 +27,7 @@ feature ArticlesController do
|
|||
fill_in 'article_tax', :with => article.tax
|
||||
fill_in 'article_deposit', :with => article.deposit
|
||||
# "Element cannot be scrolled into view" error, js as workaround
|
||||
#find('input[type="submit"]').click
|
||||
# find('input[type="submit"]').click
|
||||
page.execute_script('$("form#new_article").submit();')
|
||||
end
|
||||
expect(page).to have_content(article.name)
|
||||
|
|
@ -52,7 +51,7 @@ feature ArticlesController do
|
|||
expect(find("tr:nth-child(2) #new_articles__name").value).to eq "Pijnboompitten"
|
||||
|
||||
4.times do |i|
|
||||
all("tr:nth-child(#{i+1}) select > option")[1].select_option
|
||||
all("tr:nth-child(#{i + 1}) select > option")[1].select_option
|
||||
end
|
||||
find('input[type="submit"]').click
|
||||
expect(page).to have_content("Pijnboompitten")
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ require_relative '../spec_helper'
|
|||
|
||||
feature 'settling an order', js: true do
|
||||
let(:ftt) { create :financial_transaction_type }
|
||||
let(:admin) { create :user, groups:[create(:workgroup, role_finance: true)] }
|
||||
let(:user) { create :user, groups:[create(:ordergroup)] }
|
||||
let(:admin) { create :user, groups: [create(:workgroup, role_finance: true)] }
|
||||
let(:user) { create :user, groups: [create(:ordergroup)] }
|
||||
let(:supplier) { create :supplier }
|
||||
let(:article) { create :article, supplier: supplier, unit_quantity: 1 }
|
||||
let(:order) { create :order, supplier: supplier, article_ids: [article.id] } # need to ref article
|
||||
|
|
@ -95,7 +95,7 @@ feature 'settling an order', js: true do
|
|||
end
|
||||
|
||||
it 'deletes a GroupOrderArticle with no ordered amounts' do
|
||||
goa1.update_attributes({:quantity => 0, :tolerance => 0})
|
||||
goa1.update_attributes({ :quantity => 0, :tolerance => 0 })
|
||||
click_link article.name
|
||||
expect(page).to have_selector("#group_order_article_#{goa1.id}")
|
||||
within("#group_order_article_#{goa1.id}") do
|
||||
|
|
|
|||
|
|
@ -51,13 +51,13 @@ feature 'admin/configs' do
|
|||
end
|
||||
|
||||
def compact_hash_deep!(h)
|
||||
h.each do |k,v|
|
||||
h.each do |k, v|
|
||||
if v.is_a? Hash
|
||||
compact_hash_deep!(v)
|
||||
v.reject! {|k,v| v.blank?}
|
||||
v.reject! { |k, v| v.blank? }
|
||||
end
|
||||
end
|
||||
h.reject! {|k,v| v.blank?}
|
||||
h.reject! { |k, v| v.blank? }
|
||||
h
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
feature Order, js: true do
|
||||
let(:admin) { create :user, groups:[create(:workgroup, role_orders: true)] }
|
||||
let(:admin) { create :user, groups: [create(:workgroup, role_orders: true)] }
|
||||
let(:article) { create :article, unit_quantity: 1 }
|
||||
let(:order) { create :order, supplier: article.supplier, article_ids: [article.id] } # need to ref article
|
||||
let(:go1) { create :group_order, order: order }
|
||||
|
|
@ -21,7 +21,7 @@ feature Order, js: true do
|
|||
|
||||
it 'fills in the end date with a schedule' do
|
||||
FoodsoftConfig[:time_zone] = 'UTC'
|
||||
FoodsoftConfig[:order_schedule] = {ends: {recurr: 'FREQ=MONTHLY;BYMONTHDAY=1', time: '12:00'}}
|
||||
FoodsoftConfig[:order_schedule] = { ends: { recurr: 'FREQ=MONTHLY;BYMONTHDAY=1', time: '12:00' } }
|
||||
visit new_order_path(supplier_id: article.supplier.id)
|
||||
expect(page).to have_text I18n.t('orders.new.title')
|
||||
expect(find_field('order_ends_time_value').value).to eq '12:00'
|
||||
|
|
@ -40,7 +40,7 @@ feature Order, js: true do
|
|||
it 'can close an order' do
|
||||
setup_and_close_order
|
||||
expect(order).to be_finished
|
||||
expect(page).to_not have_link I18n.t('orders.index.action_end')
|
||||
expect(page).not_to have_link I18n.t('orders.index.action_end')
|
||||
expect(oa.units_to_order).to eq 1
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -50,10 +50,10 @@ feature 'product distribution', js: true do
|
|||
expect(oa.quantity).to eq(6)
|
||||
expect(oa.tolerance).to eq(1)
|
||||
# Gruppe a bekommt 3 einheiten.
|
||||
goa_a = oa.group_order_articles.joins(:group_order).where(:group_orders => {:ordergroup_id => user_a.ordergroup.id}).first
|
||||
goa_a = oa.group_order_articles.joins(:group_order).where(:group_orders => { :ordergroup_id => user_a.ordergroup.id }).first
|
||||
expect(goa_a.result).to eq(3)
|
||||
# gruppe b bekommt 2 einheiten.
|
||||
goa_b = oa.group_order_articles.joins(:group_order).where(:group_orders => {:ordergroup_id => user_b.ordergroup.id}).first
|
||||
goa_b = oa.group_order_articles.joins(:group_order).where(:group_orders => { :ordergroup_id => user_b.ordergroup.id }).first
|
||||
expect(goa_b.result).to eq(2)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
feature 'receiving an order', js: true do
|
||||
let(:admin) { create :user, groups:[create(:workgroup, role_orders: true)] }
|
||||
let(:admin) { create :user, groups: [create(:workgroup, role_orders: true)] }
|
||||
let(:supplier) { create :supplier }
|
||||
let(:article) { create :article, supplier: supplier, unit_quantity: 3 }
|
||||
let(:order) { create :order, supplier: supplier, article_ids: [article.id] } # need to ref article
|
||||
|
|
@ -37,53 +37,53 @@ feature 'receiving an order', js: true do
|
|||
before { login admin }
|
||||
|
||||
it 'has product ordered visible' do
|
||||
set_quantities [3,0], [0,0]
|
||||
set_quantities [3, 0], [0, 0]
|
||||
visit receive_order_path(id: order.id)
|
||||
expect(page).to have_content(article.name)
|
||||
expect(page).to have_selector("#order_article_#{oa.id}")
|
||||
end
|
||||
|
||||
it 'has product not ordered invisible' do
|
||||
set_quantities [0,0], [0,0]
|
||||
set_quantities [0, 0], [0, 0]
|
||||
visit receive_order_path(id: order.id)
|
||||
expect(page).to_not have_selector("#order_article_#{oa.id}")
|
||||
end
|
||||
|
||||
it 'is not received by default' do
|
||||
set_quantities [3,0], [0,0]
|
||||
set_quantities [3, 0], [0, 0]
|
||||
visit receive_order_path(id: order.id)
|
||||
expect(find("#order_articles_#{oa.id}_units_received").value).to be_blank
|
||||
end
|
||||
|
||||
it 'does not change anything when received is ordered' do
|
||||
set_quantities [2,0], [3,2]
|
||||
set_quantities [2, 0], [3, 2]
|
||||
visit receive_order_path(id: order.id)
|
||||
fill_in "order_articles_#{oa.id}_units_received", :with => oa.units_to_order
|
||||
find('input[type="submit"]').click
|
||||
expect(page).to have_selector('body')
|
||||
check_quantities 2, 2, 4
|
||||
check_quantities 2, 2, 4
|
||||
end
|
||||
|
||||
it 'redistributes properly when received is more' do
|
||||
set_quantities [2,0], [3,2]
|
||||
set_quantities [2, 0], [3, 2]
|
||||
visit receive_order_path(id: order.id)
|
||||
fill_in "order_articles_#{oa.id}_units_received", :with => 3
|
||||
find('input[type="submit"]').click
|
||||
expect(page).to have_selector('body')
|
||||
check_quantities 3, 2, 5
|
||||
check_quantities 3, 2, 5
|
||||
end
|
||||
|
||||
it 'redistributes properly when received is less' do
|
||||
set_quantities [2,0], [3,2]
|
||||
set_quantities [2, 0], [3, 2]
|
||||
visit receive_order_path(id: order.id)
|
||||
fill_in "order_articles_#{oa.id}_units_received", :with => 1
|
||||
find('input[type="submit"]').click
|
||||
expect(page).to have_selector('body')
|
||||
check_quantities 1, 2, 1
|
||||
check_quantities 1, 2, 1
|
||||
end
|
||||
|
||||
it 'has a locked field when edited elsewhere' do
|
||||
set_quantities [2,0], [3,2]
|
||||
set_quantities [2, 0], [3, 2]
|
||||
goa1.result = goa1.result + 1
|
||||
goa1.save!
|
||||
visit receive_order_path(id: order.id)
|
||||
|
|
@ -91,12 +91,12 @@ feature 'receiving an order', js: true do
|
|||
end
|
||||
|
||||
it 'leaves locked rows alone when submitted' do
|
||||
set_quantities [2,0], [3,2]
|
||||
set_quantities [2, 0], [3, 2]
|
||||
goa1.result = goa1.result + 1
|
||||
goa1.save!
|
||||
visit receive_order_path(id: order.id)
|
||||
find('input[type="submit"]').click
|
||||
expect(page).to have_selector('body')
|
||||
check_quantities 2, 3, 4
|
||||
check_quantities 2, 3, 4
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ feature 'the session' do
|
|||
expect(page).to_not have_selector('.alert-error')
|
||||
end
|
||||
it 'does not log me in with wrong password' do
|
||||
login user.nick, 'XX'+user.password
|
||||
login user.nick, 'XX' + user.password
|
||||
expect(page).to have_selector('.alert-error')
|
||||
end
|
||||
it 'can log me in using an email address' do
|
||||
|
|
@ -24,5 +24,4 @@ feature 'the session' do
|
|||
expect(page).to_not have_selector('.alert-error')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
# encoding: utf-8
|
||||
require_relative '../spec_helper'
|
||||
|
||||
feature 'supplier' do
|
||||
let(:supplier) { create :supplier }
|
||||
|
||||
describe 'create new' do
|
||||
let(:user) { create :user, groups:[create(:workgroup, role_suppliers: true)] }
|
||||
let(:user) { create :user, groups: [create(:workgroup, role_suppliers: true)] }
|
||||
before { login user }
|
||||
|
||||
it 'can be created' do
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ describe BankTransaction do
|
|||
JSON
|
||||
|
||||
importer = BankAccountInformationImporter.new(bank_account)
|
||||
expect{importer.import!(content)}.to raise_error(JSON::ParserError)
|
||||
expect { importer.import!(content) }.to raise_error(JSON::ParserError)
|
||||
end
|
||||
|
||||
it 'empty object' do
|
||||
|
|
|
|||
|
|
@ -92,5 +92,4 @@ describe BankTransactionReference do
|
|||
it 'returns correct value for FS34.56A67.89 with prefix and suffix' do
|
||||
expect(BankTransactionReference.parse('prefix FS34.56A67.89, suffix')).to match({ group: 34, user: 56, parts: { "A" => 67.89 } })
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -95,5 +95,4 @@ describe FoodsoftConfig do
|
|||
expect(FoodsoftConfig[:protected]['database']).to eq FoodsoftConfig[:protected][:database]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe FoodsoftMailReceiver do
|
||||
|
||||
before :all do
|
||||
@server = FoodsoftMailReceiver.new 2525, '127.0.0.1', 4, logger_severity: 5
|
||||
@server.start
|
||||
|
|
@ -75,5 +74,4 @@ describe FoodsoftMailReceiver do
|
|||
after :all do
|
||||
@server.shutdown
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ describe TokenVerifier do
|
|||
let (:msg) { v.generate }
|
||||
|
||||
it 'validates' do
|
||||
expect{ v.verify(msg) }.to_not raise_error
|
||||
expect { v.verify(msg) }.to_not raise_error
|
||||
end
|
||||
|
||||
it 'validates when recreated' do
|
||||
v2 = TokenVerifier.new(prefix)
|
||||
expect{ v2.verify(msg) }.to_not raise_error
|
||||
expect { v2.verify(msg) }.to_not raise_error
|
||||
end
|
||||
|
||||
it 'does not validate with a different prefix' do
|
||||
|
|
@ -25,20 +25,19 @@ describe TokenVerifier do
|
|||
begin
|
||||
FoodsoftConfig.scope = Faker::Lorem.words(number: 1)
|
||||
v2 = TokenVerifier.new(prefix)
|
||||
expect{ v2.verify(msg) }.to raise_error(TokenVerifier::InvalidScope)
|
||||
expect { v2.verify(msg) }.to raise_error(TokenVerifier::InvalidScope)
|
||||
ensure
|
||||
FoodsoftConfig.scope = oldscope
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not validate a random string' do
|
||||
expect{ v.verify(Faker::Lorem.characters(number: 100)) }.to raise_error(ActiveSupport::MessageVerifier::InvalidSignature)
|
||||
expect { v.verify(Faker::Lorem.characters(number: 100)) }.to raise_error(ActiveSupport::MessageVerifier::InvalidSignature)
|
||||
end
|
||||
|
||||
it 'returns the message' do
|
||||
data = [5, {'hi' => :there}, 'bye', []]
|
||||
data = [5, { 'hi' => :there }, 'bye', []]
|
||||
msg = v.generate(data)
|
||||
expect(v.verify(msg)).to eq data
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ describe Article do
|
|||
expect(article.in_open_order).to eq(order)
|
||||
end
|
||||
|
||||
|
||||
it 'has no shared article by default' do
|
||||
expect(article.shared_article).to be_nil
|
||||
end
|
||||
|
|
@ -72,8 +71,8 @@ describe Article do
|
|||
it 'can be synchronised' do
|
||||
# TODO move article sync from supplier to article
|
||||
article # need to reference for it to exist when syncing
|
||||
updated_article = supplier.sync_all[0].select{|s| s[0].id==article.id}.first[0]
|
||||
article.update_attributes updated_article.attributes.reject{|k,v| k=='id' or k=='type'}
|
||||
updated_article = supplier.sync_all[0].select { |s| s[0].id == article.id }.first[0]
|
||||
article.update_attributes updated_article.attributes.reject { |k, v| k == 'id' or k == 'type' }
|
||||
expect(article.name).to eq(shared_article.name)
|
||||
# now synchronising shouldn't change anything anymore
|
||||
expect(article.shared_article_changed?).to be_falsey
|
||||
|
|
@ -95,11 +94,11 @@ describe Article do
|
|||
article.shared_updated_on -= 1 # to make update do something
|
||||
article.save!
|
||||
# TODO get sync functionality in article
|
||||
updated_article = supplier.sync_all[0].select{|s| s[0].id==article.id}.first[0]
|
||||
article.update_attributes! updated_article.attributes.reject{|k,v| k=='id' or k=='type'}
|
||||
updated_article = supplier.sync_all[0].select { |s| s[0].id == article.id }.first[0]
|
||||
article.update_attributes! updated_article.attributes.reject { |k, v| k == 'id' or k == 'type' }
|
||||
expect(article.unit).to eq '200g'
|
||||
expect(article.unit_quantity).to eq 5
|
||||
expect(article.price).to be_within(0.005).of(shared_article.price/5)
|
||||
expect(article.price).to be_within(0.005).of(shared_article.price / 5)
|
||||
end
|
||||
|
||||
it 'does not synchronise when it has no order number' do
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ describe BankTransaction do
|
|||
expect(invoice5.paid_on).to eq bank_transaction4.date
|
||||
expect(invoice5.financial_link).to eq bank_transaction4.financial_link
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'ordergroup' do
|
||||
|
|
@ -102,7 +101,5 @@ describe BankTransaction do
|
|||
it 'ignores transaction with invalid short name' do
|
||||
expect(bank_transaction8.assign_to_ordergroup).to be false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -60,5 +60,4 @@ describe GroupOrderArticle do
|
|||
expect(res).to eq(quantity: 4, tolerance: 0, total: 4)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ describe GroupOrder do
|
|||
|
||||
# the following two tests are currently disabled - https://github.com/foodcoops/foodsoft/issues/158
|
||||
|
||||
#it 'needs an order' do
|
||||
# expect(FactoryBot.build(:group_order, ordergroup: user.ordergroup)).to be_invalid
|
||||
#end
|
||||
# it 'needs an order' do
|
||||
# expect(FactoryBot.build(:group_order, ordergroup: user.ordergroup)).to be_invalid
|
||||
# end
|
||||
|
||||
#it 'needs an ordergroup' do
|
||||
# expect(FactoryBot.build(:group_order, order: order)).to be_invalid
|
||||
#end
|
||||
# it 'needs an ordergroup' do
|
||||
# expect(FactoryBot.build(:group_order, order: order)).to be_invalid
|
||||
# end
|
||||
|
||||
describe do
|
||||
let(:go) { create :group_order, order: order, ordergroup: user.ordergroup }
|
||||
|
|
@ -21,5 +21,4 @@ describe GroupOrder do
|
|||
expect(go.price).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,12 +9,10 @@ describe OrderArticle do
|
|||
end
|
||||
|
||||
[:units_to_order, :units_billed, :units_received].each do |units|
|
||||
|
||||
it "is ordered when there are #{units.to_s.gsub '_', ' '}" do
|
||||
oa.update_attribute units, rand(1..99)
|
||||
expect(OrderArticle.ordered.count).to eq 1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it 'knows how many items there are' do
|
||||
|
|
@ -48,7 +46,7 @@ describe OrderArticle do
|
|||
end
|
||||
|
||||
describe 'redistribution' do
|
||||
let(:admin) { create :user, groups:[create(:workgroup, role_finance: true)] }
|
||||
let(:admin) { create :user, groups: [create(:workgroup, role_finance: true)] }
|
||||
let(:article) { create :article, unit_quantity: 3 }
|
||||
let(:order) { create :order, article_ids: [article.id] }
|
||||
let(:go1) { create :group_order, order: order }
|
||||
|
|
@ -74,34 +72,34 @@ describe OrderArticle do
|
|||
end
|
||||
|
||||
it 'has expected units_to_order' do
|
||||
set_quantities [3,2], [1,3], [1,0]
|
||||
expect(oa.units*oa.article.unit_quantity).to eq 6
|
||||
set_quantities [3, 2], [1, 3], [1, 0]
|
||||
expect(oa.units * oa.article.unit_quantity).to eq 6
|
||||
expect([goa1, goa2, goa3].map(&:result)).to eq [4, 1, 1]
|
||||
end
|
||||
|
||||
it 'does nothing when nothing has changed' do
|
||||
set_quantities [3,2], [1,3], [1,0]
|
||||
set_quantities [3, 2], [1, 3], [1, 0]
|
||||
expect(oa.redistribute 6, [:tolerance, nil]).to eq [1, 0]
|
||||
goa_reload
|
||||
expect([goa1, goa2, goa3].map(&:result).map(&:to_i)).to eq [4, 1, 1]
|
||||
end
|
||||
|
||||
it 'works when there is nothing to distribute' do
|
||||
set_quantities [3,2], [1,3], [1,0]
|
||||
set_quantities [3, 2], [1, 3], [1, 0]
|
||||
expect(oa.redistribute 0, [:tolerance, nil]).to eq [0, 0]
|
||||
goa_reload
|
||||
expect([goa1, goa2, goa3].map(&:result)).to eq [0, 0, 0]
|
||||
end
|
||||
|
||||
it 'works when quantity needs to be reduced' do
|
||||
set_quantities [3,2], [1,3], [1,0]
|
||||
set_quantities [3, 2], [1, 3], [1, 0]
|
||||
expect(oa.redistribute 4, [:tolerance, nil]).to eq [0, 0]
|
||||
goa_reload
|
||||
expect([goa1, goa2, goa3].map(&:result)).to eq [3, 1, 0]
|
||||
end
|
||||
|
||||
it 'works when quantity is increased within quantity' do
|
||||
set_quantities [3,0], [2,0], [2,0]
|
||||
set_quantities [3, 0], [2, 0], [2, 0]
|
||||
expect([goa1, goa2, goa3].map(&:result)).to eq [3, 2, 1]
|
||||
expect(oa.redistribute 7, [:tolerance, nil]).to eq [0, 0]
|
||||
goa_reload
|
||||
|
|
@ -109,26 +107,25 @@ describe OrderArticle do
|
|||
end
|
||||
|
||||
it 'works when there is just one for the first' do
|
||||
set_quantities [3,2], [1,3], [1,0]
|
||||
set_quantities [3, 2], [1, 3], [1, 0]
|
||||
expect(oa.redistribute 1, [:tolerance, nil]).to eq [0, 0]
|
||||
goa_reload
|
||||
expect([goa1, goa2, goa3].map(&:result)).to eq [1, 0, 0]
|
||||
end
|
||||
|
||||
it 'works when there is tolerance and left-over' do
|
||||
set_quantities [3,2], [1,1], [1,0]
|
||||
set_quantities [3, 2], [1, 1], [1, 0]
|
||||
expect(oa.redistribute 10, [:tolerance, nil]).to eq [3, 2]
|
||||
goa_reload
|
||||
expect([goa1, goa2, goa3].map(&:result)).to eq [5, 2, 1]
|
||||
end
|
||||
|
||||
it 'works when redistributing without tolerance' do
|
||||
set_quantities [3,2], [1,3], [1,0]
|
||||
set_quantities [3, 2], [1, 3], [1, 0]
|
||||
expect(oa.redistribute 8, [nil]).to eq [3]
|
||||
goa_reload
|
||||
expect([goa1, goa2, goa3].map(&:result)).to eq [3, 1, 1]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'boxfill' do
|
||||
|
|
@ -173,38 +170,37 @@ describe OrderArticle do
|
|||
context 'before the date' do
|
||||
let(:boxfill_from) { 1.hour.from_now }
|
||||
context 'decreasing the missing units' do
|
||||
include_examples "boxfill", true, [6,0]=>[5,0], [6,0,0]=>[5,0,1]
|
||||
include_examples "boxfill", true, [6, 0] => [5, 0], [6, 0, 0] => [5, 0, 1]
|
||||
end
|
||||
context 'decreasing the tolerance' do
|
||||
include_examples "boxfill", true, [1,2]=>[1,1], [1,2,3]=>[1,1,4]
|
||||
include_examples "boxfill", true, [1, 2] => [1, 1], [1, 2, 3] => [1, 1, 4]
|
||||
end
|
||||
end
|
||||
|
||||
context 'after the date' do
|
||||
let(:boxfill_from) { 1.second.ago }
|
||||
context 'changing nothing in particular' do
|
||||
include_examples "boxfill", true, [4,1]=>[4,1], [4,1,1]=>[4,1,1]
|
||||
include_examples "boxfill", true, [4, 1] => [4, 1], [4, 1, 1] => [4, 1, 1]
|
||||
end
|
||||
context 'increasing missing units' do
|
||||
include_examples "boxfill", false, [3,0]=>[2,0], [3,0,3]=>[3,0,3]
|
||||
include_examples "boxfill", false, [3, 0] => [2, 0], [3, 0, 3] => [3, 0, 3]
|
||||
end
|
||||
context 'increasing tolerance' do
|
||||
include_examples "boxfill", true, [2,1]=>[2,2], [2,1,3]=>[2,2,2]
|
||||
include_examples "boxfill", true, [2, 1] => [2, 2], [2, 1, 3] => [2, 2, 2]
|
||||
end
|
||||
context 'decreasing quantity to fix missing units' do
|
||||
include_examples "boxfill", true, [7,0]=>[6,0], [7,0,5]=>[6,0,0]
|
||||
include_examples "boxfill", true, [7, 0] => [6, 0], [7, 0, 5] => [6, 0, 0]
|
||||
end
|
||||
context 'decreasing quantity keeping missing units equal' do
|
||||
include_examples "boxfill", false, [7,0]=>[1,0], [7,0,5]=>[7,0,5]
|
||||
include_examples "boxfill", false, [7, 0] => [1, 0], [7, 0, 5] => [7, 0, 5]
|
||||
end
|
||||
context 'moving tolerance to quantity' do
|
||||
include_examples "boxfill", true, [4,2]=>[6,0], [4,2,0]=>[6,0,0]
|
||||
include_examples "boxfill", true, [4, 2] => [6, 0], [4, 2, 0] => [6, 0, 0]
|
||||
end
|
||||
# @todo enable test when tolerance doesn't count in missing_units
|
||||
#context 'decreasing tolerance' do
|
||||
# include_examples "boxfill", false, [0,2]=>[0,0], [0,2,0]=>[0,2,0]
|
||||
#end
|
||||
# context 'decreasing tolerance' do
|
||||
# include_examples "boxfill", false, [0,2]=>[0,0], [0,2,0]=>[0,2,0]
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ describe Order do
|
|||
it 'is not closed by default' do expect(order).to_not be_closed end
|
||||
|
||||
it 'has valid order articles' do
|
||||
order.order_articles.each {|oa| expect(oa).to be_valid }
|
||||
order.order_articles.each { |oa| expect(oa).to be_valid }
|
||||
end
|
||||
|
||||
it 'can be finished' do
|
||||
|
|
@ -117,13 +117,12 @@ describe Order do
|
|||
expect(order).to_not be_open
|
||||
expect(order).to be_closed
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'with a default end date' do
|
||||
let(:order) { create :order }
|
||||
before do
|
||||
FoodsoftConfig[:order_schedule] = {ends: {recurr: 'FREQ=WEEKLY;BYDAY=MO', time: '9:00'}}
|
||||
FoodsoftConfig[:order_schedule] = { ends: { recurr: 'FREQ=WEEKLY;BYDAY=MO', time: '9:00' } }
|
||||
order.init_dates
|
||||
end
|
||||
|
||||
|
|
@ -134,7 +133,6 @@ describe Order do
|
|||
it 'to have a correct time' do
|
||||
expect(order.ends.strftime('%H:%M')).to eq '09:00'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'mapped to GroupOrders' do
|
||||
|
|
@ -153,5 +151,4 @@ describe Order do
|
|||
expect(orders[1][:group_order]).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ describe Ordergroup do
|
|||
let(:ftt1) { create :financial_transaction_type, financial_transaction_class: ftc1 }
|
||||
let(:ftt2) { create :financial_transaction_type, financial_transaction_class: ftc2 }
|
||||
let(:ftt3) { create :financial_transaction_type, financial_transaction_class: ftc2 }
|
||||
let(:user) { create :user, groups:[create(:ordergroup)] }
|
||||
let(:user) { create :user, groups: [create(:ordergroup)] }
|
||||
|
||||
context 'with financial transactions' do
|
||||
before do
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ describe Supplier do
|
|||
|
||||
it 'has valid articles' do
|
||||
supplier = create :supplier, article_count: true
|
||||
supplier.articles.each {|a| expect(a).to be_valid }
|
||||
supplier.articles.each { |a| expect(a).to be_valid }
|
||||
end
|
||||
|
||||
context 'connected to a shared supplier' do
|
||||
|
|
@ -91,5 +91,4 @@ describe Supplier do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
require_relative '../spec_helper'
|
||||
|
||||
describe User do
|
||||
|
||||
it 'is correctly created' do
|
||||
user = create :user,
|
||||
nick: 'johnnydoe', first_name: 'Johnny', last_name: 'DoeBar',
|
||||
email: 'johnnydoe@foodcoop.test', phone: '+1234567890'
|
||||
nick: 'johnnydoe', first_name: 'Johnny', last_name: 'DoeBar',
|
||||
email: 'johnnydoe@foodcoop.test', phone: '+1234567890'
|
||||
expect(user.nick).to eq('johnnydoe')
|
||||
expect(user.first_name).to eq('Johnny')
|
||||
expect(user.last_name).to eq('DoeBar')
|
||||
|
|
@ -71,5 +70,4 @@ describe User do
|
|||
let(:user) { create :admin }
|
||||
it 'default admin role' do expect(user.role_admin?).to be_truthy end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ require 'capybara/apparition'
|
|||
Capybara.server = :puma, { Silent: true }
|
||||
Capybara.javascript_driver = :apparition
|
||||
|
||||
#TODO: Remove temporary fix to ignore JavaScript errors
|
||||
# TODO: Remove temporary fix to ignore JavaScript errors
|
||||
Capybara.register_driver :apparition do |app|
|
||||
Capybara::Apparition::Driver.new(app, {js_errors: false})
|
||||
Capybara::Apparition::Driver.new(app, { js_errors: false })
|
||||
end
|
||||
|
||||
# Requires supporting ruby files with custom matchers and macros, etc,
|
||||
|
|
@ -70,7 +70,7 @@ end
|
|||
# include default foodsoft scope in urls, so that *_path works
|
||||
# https://github.com/rspec/rspec-rails/issues/255
|
||||
class ActionDispatch::Routing::RouteSet
|
||||
def default_url_options(options={})
|
||||
{foodcoop: FoodsoftConfig.scope}.merge(options)
|
||||
def default_url_options(options = {})
|
||||
{ foodcoop: FoodsoftConfig.scope }.merge(options)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ module ApiHelper
|
|||
let(:api_access_token) { create(:oauth2_access_token, resource_owner_id: user.id, scopes: api_scopes&.join(' ')).token }
|
||||
let(:api_authorization) { "Bearer #{api_access_token}" }
|
||||
|
||||
def self.it_handles_invalid_token(method, path, params_block = ->{ api_auth })
|
||||
def self.it_handles_invalid_token(method, path, params_block = -> { api_auth })
|
||||
context 'with invalid access token' do
|
||||
let(:api_access_token) { 'abc' }
|
||||
it { is_expected.to validate(method, path, 401, instance_exec(¶ms_block)) }
|
||||
end
|
||||
end
|
||||
|
||||
def self.it_handles_invalid_scope(method, path, params_block = ->{ api_auth })
|
||||
def self.it_handles_invalid_scope(method, path, params_block = -> { api_auth })
|
||||
context 'with invalid scope' do
|
||||
let(:api_scopes) { ['none'] }
|
||||
it { is_expected.to validate(method, path, 403, instance_exec(¶ms_block)) }
|
||||
|
|
@ -32,7 +32,6 @@ module ApiHelper
|
|||
# @return Query parameters with authentication header
|
||||
# @see Swagger::RspecHelpers#validate
|
||||
def api_auth(params = {})
|
||||
{'_headers' => {'Authorization' => api_authorization }}.deep_merge(params)
|
||||
{ '_headers' => { 'Authorization' => api_authorization } }.deep_merge(params)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,4 +7,3 @@ module Faker
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
# @see http://stackoverflow.com/a/11048669/2866660
|
||||
def scrolldown
|
||||
page.execute_script "window.scrollBy(0,10000)"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
module SessionHelper
|
||||
|
||||
def login(user=nil, password=nil)
|
||||
def login(user = nil, password = nil)
|
||||
visit login_path
|
||||
user = FactoryBot.create :user if user.nil?
|
||||
if user.instance_of? ::User
|
||||
|
|
@ -13,5 +11,4 @@ module SessionHelper
|
|||
fill_in 'password', :with => password
|
||||
find('input[type=submit]').click
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ ActiveSupport.on_load(:after_initialize) do
|
|||
def category
|
||||
ArticleCategory.where(id: article_category_id).first
|
||||
end
|
||||
|
||||
def self.find_by_number(n)
|
||||
find_by_order_number(n)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue