Auto correct rubocop style issues

This commit is contained in:
Patrick Gansterer 2022-02-20 16:15:22 +01:00
parent f260e607bf
commit 7e8c1d041d
39 changed files with 115 additions and 199 deletions

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -14,13 +14,13 @@ FactoryBot.define do
article_category
end
factory :shared_article, class: SharedArticle do
factory :shared_article, class: 'SharedArticle' do
sequence(:name) { |n| Faker::Lorem.words(number: rand(2..4)).join(' ') + " s##{n}" }
order_number { Faker::Lorem.characters(number: rand(1..12)) }
shared_supplier
end
factory :stock_article, class: StockArticle do
factory :stock_article, class: 'StockArticle' do
sequence(:name) { |n| Faker::Lorem.words(number: rand(2..4)).join(' ') + " ##{n}" }
unit_quantity { 1 }
supplier

View file

@ -2,12 +2,12 @@ require 'factory_bot'
require 'doorkeeper'
FactoryBot.define do
factory :oauth2_application, class: Doorkeeper::Application do
factory :oauth2_application, class: 'Doorkeeper::Application' do
name { Faker::App.name }
redirect_uri { 'https://example.com:1234/app' }
end
factory :oauth2_access_token, class: Doorkeeper::AccessToken do
factory :oauth2_access_token, class: 'Doorkeeper::AccessToken' do
application factory: :oauth2_application
end
end

View file

@ -23,7 +23,7 @@ FactoryBot.define do
create_list :article, article_count, supplier: supplier
end
factory :shared_supplier, class: SharedSupplier
factory :shared_supplier, class: 'SharedSupplier'
end
factory :supplier_category do

View file

@ -2,8 +2,9 @@ require_relative '../spec_helper'
feature ArticlesController do
let(:user) { create :user, groups: [create(:workgroup, role_article_meta: true)] }
let (:supplier) { create :supplier }
let(:supplier) { create :supplier }
let!(:article_category) { create :article_category }
before { login user }
describe ':index', js: true do
@ -17,7 +18,7 @@ feature ArticlesController do
it 'can create a new article' do
click_on I18n.t('articles.index.new')
expect(page).to have_selector('form#new_article')
article = FactoryBot.build :article, supplier: supplier, article_category: article_category
article = build :article, supplier: supplier, article_category: article_category
within('#new_article') do
fill_in 'article_name', :with => article.name
fill_in 'article_unit', :with => article.unit
@ -37,6 +38,7 @@ feature ArticlesController do
describe ':upload' do
let(:filename) { 'foodsoft_file_02.csv' }
let(:file) { Rails.root.join("spec/fixtures/#{filename}") }
before do
visit upload_supplier_articles_path(supplier_id: supplier.id)
attach_file 'articles_file', file
@ -45,6 +47,7 @@ feature ArticlesController do
Dir.glob('spec/fixtures/foodsoft_file_01.*') do |test_file|
describe "can import articles from #{test_file}" do
let(:file) { Rails.root.join(test_file) }
it do
find('input[type="submit"]').click
expect(find("tr:nth-child(1) #new_articles__note").value).to eq "bio ◎"
@ -63,6 +66,7 @@ feature ArticlesController do
describe "can update existing article" do
let!(:article) { create :article, supplier: supplier, name: 'Foobar', order_number: 1, unit: '250 g' }
it do
find('input[type="submit"]').click
expect(find("#articles_#{article.id}_name").value).to eq 'Tomatoes'
@ -88,6 +92,7 @@ feature ArticlesController do
describe "can remove an existing article" do
let!(:article) { create :article, supplier: supplier, name: 'Foobar', order_number: 99999 }
it do
check('articles_outlist_absent')
find('input[type="submit"]').click
@ -101,6 +106,7 @@ feature ArticlesController do
describe "can convert units when updating" do
let!(:article) { create :article, supplier: supplier, order_number: 1, unit: '250 g' }
it do
check('articles_convert_units')
find('input[type="submit"]').click

View file

@ -12,6 +12,7 @@ feature 'settling an order', js: true do
let(:oa) { order.order_articles.find_by_article_id(article.id) }
let(:goa1) { create :group_order_article, group_order: go1, order_article: oa }
let(:goa2) { create :group_order_article, group_order: go2, order_article: oa }
before do
goa1.update_quantities(3, 0)
goa2.update_quantities(1, 0)
@ -29,6 +30,7 @@ feature 'settling an order', js: true do
end
before { login admin }
before { visit new_finance_order_path(order_id: order.id) }
it 'has product ordered visible' do

View file

@ -5,6 +5,7 @@ feature LoginController do
describe 'forgot password' do
before { visit forgot_password_path }
it 'is accessible' do
expect(page).to have_selector 'input[id=user_email]'
end
@ -21,7 +22,9 @@ feature LoginController do
describe 'and reset it' do
let(:token) { user.reset_password_token }
let(:newpass) { user.new_random_password }
before { user.request_password_reset! }
before { visit new_password_path(id: user.id, token: token) }
it 'is accessible' do
@ -30,6 +33,7 @@ feature LoginController do
describe 'with wrong token' do
let(:token) { 'foobar' }
it 'is not accessible' do
expect(page).to have_selector '.alert-error'
expect(page).to_not have_selector 'input[type=password]'

View file

@ -8,14 +8,17 @@ feature 'the session' do
visit login_path
expect(page).to have_selector('input[type=password]')
end
it 'logs me in' do
login user
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
expect(page).to have_selector('.alert-error')
end
it 'can log me in using an email address' do
visit login_path
fill_in 'nick', :with => user.email

View file

@ -5,6 +5,7 @@ feature 'supplier' do
describe 'create new' do
let(:user) { create :user, groups: [create(:workgroup, role_suppliers: true)] }
before { login user }
it 'can be created' do

View file

@ -1,9 +1,9 @@
require_relative '../spec_helper'
describe TokenVerifier do
let (:prefix) { 'xyz' }
let (:v) { TokenVerifier.new(prefix) }
let (:msg) { v.generate }
let(:prefix) { 'xyz' }
let(:v) { TokenVerifier.new(prefix) }
let(:msg) { v.generate }
it 'validates' do
expect { v.verify(msg) }.to_not raise_error

View file

@ -5,7 +5,7 @@ describe Article do
let(:article) { create :article, supplier: supplier }
it 'has a unique name' do
article2 = FactoryBot.build :article, supplier: supplier, name: article.name
article2 = build :article, supplier: supplier, name: article.name
expect(article2).to be_invalid
end

View file

@ -130,6 +130,7 @@ describe OrderArticle do
describe 'boxfill' do
before { FoodsoftConfig[:use_boxfill] = true }
let(:article) { create :article, unit_quantity: 6 }
let(:order) { create :order, article_ids: [article.id], starts: 1.week.ago }
let(:oa) { order.order_articles.first }
@ -139,7 +140,7 @@ describe OrderArticle do
shared_examples "boxfill" do |success, q|
# initial situation
before do
goa.update_quantities *q.keys[0]
goa.update_quantities(*q.keys[0])
oa.update_results!; oa.reload
end
@ -149,11 +150,11 @@ describe OrderArticle do
end
# actual test
it (success ? 'succeeds' : 'fails') do
it(success ? 'succeeds' : 'fails') do
order.update_attributes(boxfill: boxfill_from)
r = proc {
goa.update_quantities *q.values[0]
goa.update_quantities(*q.values[0])
oa.update_results!
}
if success
@ -169,9 +170,11 @@ 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]
end
context 'decreasing the tolerance' do
include_examples "boxfill", true, [1, 2] => [1, 1], [1, 2, 3] => [1, 1, 4]
end
@ -179,21 +182,27 @@ describe OrderArticle do
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]
end
context 'increasing missing units' do
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]
end
context 'decreasing quantity to fix missing units' do
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]
end
context 'moving tolerance to quantity' do
include_examples "boxfill", true, [4, 2] => [6, 0], [4, 2, 0] => [6, 0, 0]
end

View file

@ -24,46 +24,46 @@ describe Order do
let!(:received_order) { create :order, state: 'received' }
let!(:closed_order) { create :order, state: 'closed' }
it 'should retrieve open orders in the "open" scope' do
it 'retrieves open orders in the "open" scope' do
expect(Order.open.count).to eq(1)
expect(Order.open.where(id: open_order.id)).to exist
end
it 'should retrieve finished, received and closed orders in the "finished" scope' do
it 'retrieves finished, received and closed orders in the "finished" scope' do
expect(Order.finished.count).to eq(3)
expect(Order.finished.where(id: finished_order.id)).to exist
expect(Order.finished.where(id: received_order.id)).to exist
expect(Order.finished.where(id: closed_order.id)).to exist
end
it 'should retrieve finished and received orders in the "finished_not_closed" scope' do
it 'retrieves finished and received orders in the "finished_not_closed" scope' do
expect(Order.finished_not_closed.count).to eq(2)
expect(Order.finished_not_closed.where(id: finished_order.id)).to exist
expect(Order.finished_not_closed.where(id: received_order.id)).to exist
end
it 'should return valid boolean states for open orders' do
it 'returns valid boolean states for open orders' do
expect(open_order.open?).to be(true)
expect(open_order.finished?).to be(false)
expect(open_order.received?).to be(false)
expect(open_order.closed?).to be(false)
end
it 'should return valid boolean states for finished orders' do
it 'returns valid boolean states for finished orders' do
expect(finished_order.open?).to be(false)
expect(finished_order.finished?).to be(true)
expect(finished_order.received?).to be(false)
expect(finished_order.closed?).to be(false)
end
it 'should return valid boolean states for received orders' do
it 'returns valid boolean states for received orders' do
expect(received_order.open?).to be(false)
expect(received_order.finished?).to be(true)
expect(received_order.received?).to be(true)
expect(received_order.closed?).to be(false)
end
it 'should return valid boolean states for closed orders' do
it 'returns valid boolean states for closed orders' do
expect(closed_order.open?).to be(false)
expect(closed_order.finished?).to be(false)
expect(closed_order.received?).to be(false)
@ -122,6 +122,7 @@ describe Order do
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' } }
order.init_dates

View file

@ -15,6 +15,7 @@ describe User do
describe 'does not have the role' do
let(:user) { create :user }
it 'admin' do expect(user.role_admin?).to be_falsey end
it 'finance' do expect(user.role_finance?).to be_falsey end
it 'article_meta' do expect(user.role_article_meta?).to be_falsey end
@ -28,20 +29,25 @@ describe User do
it 'can authenticate with correct password' do
expect(User.authenticate(user.nick, 'blahblahblah')).to be_truthy
end
it 'can not authenticate with incorrect password' do
expect(User.authenticate(user.nick, 'foobar')).to be_nil
end
it 'can not authenticate with nil nick' do
expect(User.authenticate(nil, 'blahblahblah')).to be_nil
end
it 'can not authenticate with nil password' do
expect(User.authenticate(user.nick, nil)).to be_nil
end
it 'can not set a password without matching confirmation' do
user.password = 'abcdefghijkl'
user.password_confirmation = 'foobaruvwxyz'
expect(user).to be_invalid
end
it 'can set a password with matching confirmation' do
user.password = 'abcdefghijkl'
user.password_confirmation = 'abcdefghijkl'
@ -51,6 +57,7 @@ describe User do
it 'has a unique nick' do
expect(build(:user, nick: user.nick, email: "x-#{user.email}")).to be_invalid
end
it 'has a unique email' do
expect(build(:user, email: "#{user.email}")).to be_invalid
end
@ -68,6 +75,7 @@ describe User do
describe 'admin' do
let(:user) { create :admin }
it 'default admin role' do expect(user.role_admin?).to be_truthy end
end
end

View file

@ -10,6 +10,7 @@ module ApiHelper
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(&params_block)) }
end
end
@ -17,6 +18,7 @@ module ApiHelper
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(&params_block)) }
end
end

View file

@ -7,6 +7,7 @@ module ApiOAuth
let(:api_scopes) { [] } # empty scopes for stricter testing (in reality this would be default_scopes)
let(:api_access_token) { double(:acceptable? => true, :accessible? => true, scopes: api_scopes) }
before { allow(controller).to receive(:doorkeeper_token) { api_access_token } }
before { allow(controller).to receive(:current_user) { user } }
let(:json_response) { JSON.parse(response.body) }