Auto correct rubocop style issues
This commit is contained in:
parent
f260e607bf
commit
7e8c1d041d
39 changed files with 115 additions and 199 deletions
|
@ -54,13 +54,6 @@ Lint/AmbiguousBlockAssociation:
|
||||||
- 'spec/api/v1/user/group_order_articles_spec.rb'
|
- 'spec/api/v1/user/group_order_articles_spec.rb'
|
||||||
- 'spec/models/article_spec.rb'
|
- 'spec/models/article_spec.rb'
|
||||||
|
|
||||||
# Offense count: 4
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
Lint/AmbiguousOperator:
|
|
||||||
Exclude:
|
|
||||||
- 'app/mailers/mailer.rb'
|
|
||||||
- 'spec/models/order_article_spec.rb'
|
|
||||||
|
|
||||||
# Offense count: 4
|
# Offense count: 4
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
Lint/AmbiguousOperatorPrecedence:
|
Lint/AmbiguousOperatorPrecedence:
|
||||||
|
@ -134,12 +127,6 @@ Lint/IneffectiveAccessModifier:
|
||||||
- 'lib/foodsoft_mail_receiver.rb'
|
- 'lib/foodsoft_mail_receiver.rb'
|
||||||
- 'lib/token_verifier.rb'
|
- 'lib/token_verifier.rb'
|
||||||
|
|
||||||
# Offense count: 1
|
|
||||||
# Cop supports --auto-correct-all.
|
|
||||||
Lint/InterpolationCheck:
|
|
||||||
Exclude:
|
|
||||||
- 'db/migrate/007_create_article_prices.rb'
|
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct-all.
|
# Cop supports --auto-correct-all.
|
||||||
Lint/Loop:
|
Lint/Loop:
|
||||||
|
@ -158,32 +145,11 @@ Lint/NonDeterministicRequireOrder:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'spec/spec_helper.rb'
|
- 'spec/spec_helper.rb'
|
||||||
|
|
||||||
# Offense count: 5
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
Lint/ParenthesesAsGroupedExpression:
|
|
||||||
Exclude:
|
|
||||||
- 'spec/integration/articles_spec.rb'
|
|
||||||
- 'spec/lib/token_verifier_spec.rb'
|
|
||||||
- 'spec/models/order_article_spec.rb'
|
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
Lint/ReturnInVoidContext:
|
Lint/ReturnInVoidContext:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/foodsoft_config.rb'
|
- 'lib/foodsoft_config.rb'
|
||||||
|
|
||||||
# Offense count: 8
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
Lint/ScriptPermission:
|
|
||||||
Exclude:
|
|
||||||
- 'Rakefile'
|
|
||||||
- 'plugins/discourse/Rakefile'
|
|
||||||
- 'plugins/documents/Rakefile'
|
|
||||||
- 'plugins/links/Rakefile'
|
|
||||||
- 'plugins/messages/Rakefile'
|
|
||||||
- 'plugins/polls/Rakefile'
|
|
||||||
- 'plugins/printer/Rakefile'
|
|
||||||
- 'plugins/wiki/Rakefile'
|
|
||||||
|
|
||||||
# Offense count: 7
|
# Offense count: 7
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
Lint/SendWithMixinArgument:
|
Lint/SendWithMixinArgument:
|
||||||
|
@ -479,71 +445,11 @@ RSpec/DescribedClass:
|
||||||
- 'spec/models/ordergroup_spec.rb'
|
- 'spec/models/ordergroup_spec.rb'
|
||||||
- 'spec/models/user_spec.rb'
|
- 'spec/models/user_spec.rb'
|
||||||
|
|
||||||
# Offense count: 9
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: AllowConsecutiveOneLiners.
|
|
||||||
RSpec/EmptyLineAfterExample:
|
|
||||||
Exclude:
|
|
||||||
- 'spec/integration/session_spec.rb'
|
|
||||||
- 'spec/models/user_spec.rb'
|
|
||||||
|
|
||||||
# Offense count: 6
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
RSpec/EmptyLineAfterExampleGroup:
|
|
||||||
Exclude:
|
|
||||||
- 'spec/models/order_article_spec.rb'
|
|
||||||
|
|
||||||
# Offense count: 30
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
RSpec/EmptyLineAfterFinalLet:
|
|
||||||
Exclude:
|
|
||||||
- 'spec/api/v1/order_articles_spec.rb'
|
|
||||||
- 'spec/api/v1/swagger_spec.rb'
|
|
||||||
- 'spec/api/v1/user/financial_transactions_spec.rb'
|
|
||||||
- 'spec/api/v1/user/group_order_articles_spec.rb'
|
|
||||||
- 'spec/integration/articles_spec.rb'
|
|
||||||
- 'spec/integration/balancing_spec.rb'
|
|
||||||
- 'spec/integration/login_spec.rb'
|
|
||||||
- 'spec/integration/supplier_spec.rb'
|
|
||||||
- 'spec/models/order_article_spec.rb'
|
|
||||||
- 'spec/models/order_spec.rb'
|
|
||||||
- 'spec/models/user_spec.rb'
|
|
||||||
- 'spec/support/api_helper.rb'
|
|
||||||
|
|
||||||
# Offense count: 17
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
RSpec/EmptyLineAfterHook:
|
|
||||||
Exclude:
|
|
||||||
- 'spec/api/v1/swagger_spec.rb'
|
|
||||||
- 'spec/api/v1/user/financial_transactions_spec.rb'
|
|
||||||
- 'spec/api/v1/user/group_order_articles_spec.rb'
|
|
||||||
- 'spec/integration/balancing_spec.rb'
|
|
||||||
- 'spec/integration/login_spec.rb'
|
|
||||||
- 'spec/models/order_article_spec.rb'
|
|
||||||
- 'spec/support/api_oauth.rb'
|
|
||||||
|
|
||||||
# Offense count: 59
|
# Offense count: 59
|
||||||
# Configuration parameters: CountAsOne.
|
# Configuration parameters: CountAsOne.
|
||||||
RSpec/ExampleLength:
|
RSpec/ExampleLength:
|
||||||
Max: 81
|
Max: 81
|
||||||
|
|
||||||
# Offense count: 7
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: CustomTransform, IgnoredWords.
|
|
||||||
RSpec/ExampleWording:
|
|
||||||
Exclude:
|
|
||||||
- 'spec/models/order_spec.rb'
|
|
||||||
|
|
||||||
# Offense count: 5
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: Include.
|
|
||||||
# Include: spec/factories.rb, spec/factories/**/*.rb, features/support/factories/**/*.rb
|
|
||||||
RSpec/FactoryBot/FactoryClassName:
|
|
||||||
Exclude:
|
|
||||||
- 'spec/factories/article.rb'
|
|
||||||
- 'spec/factories/doorkeeper.rb'
|
|
||||||
- 'spec/factories/supplier.rb'
|
|
||||||
|
|
||||||
# Offense count: 2
|
# Offense count: 2
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
RSpec/FactoryBot/SyntaxMethods:
|
RSpec/FactoryBot/SyntaxMethods:
|
||||||
|
@ -599,12 +505,6 @@ RSpec/IteratedExpectation:
|
||||||
- 'spec/models/order_spec.rb'
|
- 'spec/models/order_spec.rb'
|
||||||
- 'spec/models/supplier_spec.rb'
|
- 'spec/models/supplier_spec.rb'
|
||||||
|
|
||||||
# Offense count: 3
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
RSpec/LetBeforeExamples:
|
|
||||||
Exclude:
|
|
||||||
- 'spec/api/v1/swagger_spec.rb'
|
|
||||||
|
|
||||||
# Offense count: 13
|
# Offense count: 13
|
||||||
RSpec/LetSetup:
|
RSpec/LetSetup:
|
||||||
Exclude:
|
Exclude:
|
||||||
|
@ -674,14 +574,6 @@ RSpec/RepeatedExample:
|
||||||
- 'spec/lib/bank_transaction_reference_spec.rb'
|
- 'spec/lib/bank_transaction_reference_spec.rb'
|
||||||
- 'spec/lib/foodsoft_mail_receiver_spec.rb'
|
- 'spec/lib/foodsoft_mail_receiver_spec.rb'
|
||||||
|
|
||||||
# Offense count: 9
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
RSpec/ScatteredLet:
|
|
||||||
Exclude:
|
|
||||||
- 'spec/api/v1/swagger_spec.rb'
|
|
||||||
- 'spec/api/v1/user/group_order_articles_spec.rb'
|
|
||||||
- 'spec/api/v1/user/ordergroup_spec.rb'
|
|
||||||
|
|
||||||
# Offense count: 7
|
# Offense count: 7
|
||||||
RSpec/ScatteredSetup:
|
RSpec/ScatteredSetup:
|
||||||
Exclude:
|
Exclude:
|
||||||
|
@ -710,14 +602,6 @@ Rails/ActiveRecordCallbacksOrder:
|
||||||
- 'app/models/order.rb'
|
- 'app/models/order.rb'
|
||||||
- 'app/models/stock_change.rb'
|
- 'app/models/stock_change.rb'
|
||||||
|
|
||||||
# Offense count: 2
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: Include.
|
|
||||||
# Include: db/migrate/*.rb
|
|
||||||
Rails/AddColumnIndex:
|
|
||||||
Exclude:
|
|
||||||
- 'db/migrate/20171002000000_create_financial_links.rb'
|
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
Rails/ApplicationMailer:
|
Rails/ApplicationMailer:
|
||||||
|
@ -751,12 +635,6 @@ Rails/Blank:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'app/controllers/api/v1/base_controller.rb'
|
- 'app/controllers/api/v1/base_controller.rb'
|
||||||
|
|
||||||
# Offense count: 1
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
Rails/ContentTag:
|
|
||||||
Exclude:
|
|
||||||
- 'plugins/wiki/app/helpers/pages_helper.rb'
|
|
||||||
|
|
||||||
# Offense count: 33
|
# Offense count: 33
|
||||||
# Configuration parameters: Include.
|
# Configuration parameters: Include.
|
||||||
# Include: db/migrate/*.rb
|
# Include: db/migrate/*.rb
|
||||||
|
@ -783,12 +661,6 @@ Rails/Date:
|
||||||
Rails/DynamicFindBy:
|
Rails/DynamicFindBy:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
# Offense count: 1
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
Rails/EagerEvaluationLogMessage:
|
|
||||||
Exclude:
|
|
||||||
- 'db/migrate/20130718183101_migrate_user_settings.rb'
|
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: Include.
|
# Configuration parameters: Include.
|
||||||
|
@ -1297,15 +1169,6 @@ Style/ExplicitBlockArgument:
|
||||||
- 'plugins/current_orders/app/documents/multiple_orders_by_articles.rb'
|
- 'plugins/current_orders/app/documents/multiple_orders_by_articles.rb'
|
||||||
- 'plugins/current_orders/app/documents/multiple_orders_by_groups.rb'
|
- 'plugins/current_orders/app/documents/multiple_orders_by_groups.rb'
|
||||||
|
|
||||||
# Offense count: 4
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
Style/FileWrite:
|
|
||||||
Exclude:
|
|
||||||
- 'config/initializers/secret_token.rb'
|
|
||||||
- 'lib/order_txt.rb'
|
|
||||||
- 'lib/render_csv.rb'
|
|
||||||
- 'lib/render_pdf.rb'
|
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct-all.
|
# Cop supports --auto-correct-all.
|
||||||
# Configuration parameters: EnforcedStyle.
|
# Configuration parameters: EnforcedStyle.
|
||||||
|
@ -1462,12 +1325,6 @@ Style/LineEndConcatenation:
|
||||||
- 'db/migrate/20130702113610_update_group_order_totals.rb'
|
- 'db/migrate/20130702113610_update_group_order_totals.rb'
|
||||||
- 'plugins/current_orders/app/documents/multiple_orders_by_articles.rb'
|
- 'plugins/current_orders/app/documents/multiple_orders_by_articles.rb'
|
||||||
|
|
||||||
# Offense count: 1
|
|
||||||
# Cop supports --auto-correct-all.
|
|
||||||
Style/MapToHash:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/foodsoft_config.rb'
|
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: IgnoredMethods.
|
# Configuration parameters: IgnoredMethods.
|
||||||
|
@ -1780,12 +1637,6 @@ Style/RedundantReturn:
|
||||||
Style/RedundantSelf:
|
Style/RedundantSelf:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
# Offense count: 1
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
Style/RedundantSelfAssignmentBranch:
|
|
||||||
Exclude:
|
|
||||||
- 'db/migrate/20130718183101_migrate_user_settings.rb'
|
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct-all.
|
# Cop supports --auto-correct-all.
|
||||||
Style/RedundantSort:
|
Style/RedundantSort:
|
||||||
|
|
0
Rakefile
Normal file → Executable file
0
Rakefile
Normal file → Executable file
|
@ -145,13 +145,13 @@ class Mailer < ActionMailer::Base
|
||||||
|
|
||||||
def self.deliver_now_with_user_locale(user, &block)
|
def self.deliver_now_with_user_locale(user, &block)
|
||||||
I18n.with_locale(user.settings['profile']['language']) do
|
I18n.with_locale(user.settings['profile']['language']) do
|
||||||
self.deliver_now &block
|
self.deliver_now(&block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.deliver_now_with_default_locale(&block)
|
def self.deliver_now_with_default_locale(&block)
|
||||||
I18n.with_locale(FoodsoftConfig[:default_locale]) do
|
I18n.with_locale(FoodsoftConfig[:default_locale]) do
|
||||||
self.deliver_now &block
|
self.deliver_now(&block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ Foodsoft::Application.config.secret_key_base = begin
|
||||||
else
|
else
|
||||||
puts "=> Generating initial SECRET_KEY_BASE in #{sf}"
|
puts "=> Generating initial SECRET_KEY_BASE in #{sf}"
|
||||||
token = SecureRandom.hex(30)
|
token = SecureRandom.hex(30)
|
||||||
File.open(sf, 'w') { |f| f.write(token) }
|
File.write(sf, token)
|
||||||
token
|
token
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@ class CreateArticlePrices < ActiveRecord::Migration[4.2]
|
||||||
puts 'add prices to the sample articles'
|
puts 'add prices to the sample articles'
|
||||||
CreateArticles::SAMPLE_ARTICLE_NAMES.each do |a|
|
CreateArticles::SAMPLE_ARTICLE_NAMES.each do |a|
|
||||||
puts 'Create Price for article ' + a
|
puts 'Create Price for article ' + a
|
||||||
raise 'article #{a} not found!' unless article = Article.find_by_name(a)
|
raise "article #{a} not found!" unless article = Article.find_by_name(a)
|
||||||
|
|
||||||
new_price = ArticlePrice.new(:clear_price => rand(4) + 1,
|
new_price = ArticlePrice.new(:clear_price => rand(4) + 1,
|
||||||
:tax => 7.0,
|
:tax => 7.0,
|
||||||
|
|
|
@ -16,7 +16,7 @@ class MigrateUserSettings < ActiveRecord::Migration[4.2]
|
||||||
begin
|
begin
|
||||||
user = type.constantize.find(id)
|
user = type.constantize.find(id)
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
Rails.logger.debug "Can't find configurable object with type: #{type.inspect}, id: #{id.inspect}"
|
Rails.logger.debug { "Can't find configurable object with type: #{type.inspect}, id: #{id.inspect}" }
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class MigrateUserSettings < ActiveRecord::Migration[4.2]
|
||||||
|
|
||||||
# prepare value
|
# prepare value
|
||||||
value = YAML.load(old_setting.value)
|
value = YAML.load(old_setting.value)
|
||||||
value = value.nil? ? false : value
|
value = false if value.nil?
|
||||||
|
|
||||||
# set the settings_attributes (thanks to settings.merge! we can set them one by one)
|
# set the settings_attributes (thanks to settings.merge! we can set them one by one)
|
||||||
user.settings_attributes = {
|
user.settings_attributes = {
|
||||||
|
|
|
@ -4,7 +4,10 @@ class CreateFinancialLinks < ActiveRecord::Migration[4.2]
|
||||||
t.text :note
|
t.text :note
|
||||||
end
|
end
|
||||||
|
|
||||||
add_column :financial_transactions, :financial_link_id, :integer, index: true
|
add_column :financial_transactions, :financial_link_id, :integer
|
||||||
add_column :invoices, :financial_link_id, :integer, index: true
|
add_column :invoices, :financial_link_id, :integer
|
||||||
|
|
||||||
|
add_index :financial_transactions, :financial_link_id
|
||||||
|
add_index :invoices, :financial_link_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -158,7 +158,7 @@ class FoodsoftConfig
|
||||||
# @return [Array<String>] Valid names of foodcoops.
|
# @return [Array<String>] Valid names of foodcoops.
|
||||||
def foodcoops
|
def foodcoops
|
||||||
if config[:multi_coop_install]
|
if config[:multi_coop_install]
|
||||||
APP_CONFIG.keys.reject { |coop| coop =~ /^(default|development|test|production)$/ }
|
APP_CONFIG.keys.grep_v(/^(default|development|test|production)$/)
|
||||||
else
|
else
|
||||||
[config[:default_scope]]
|
[config[:default_scope]]
|
||||||
end
|
end
|
||||||
|
@ -189,7 +189,7 @@ class FoodsoftConfig
|
||||||
|
|
||||||
# @return [Hash] Full configuration.
|
# @return [Hash] Full configuration.
|
||||||
def to_hash
|
def to_hash
|
||||||
keys.map { |k| [k, self[k]] }.to_h
|
keys.to_h { |k| [k, self[k]] }
|
||||||
end
|
end
|
||||||
|
|
||||||
# for using active_model_serializer in the api/v1/configs controller
|
# for using active_model_serializer in the api/v1/configs controller
|
||||||
|
|
|
@ -25,6 +25,6 @@ class OrderTxt
|
||||||
|
|
||||||
# Helper method to test pdf via rails console: OrderTxt.new(order).save_tmp
|
# Helper method to test pdf via rails console: OrderTxt.new(order).save_tmp
|
||||||
def save_tmp
|
def save_tmp
|
||||||
File.open("#{Rails.root}/tmp/#{self.class.to_s.underscore}.txt", 'w') { |f| f.write(to_csv.force_encoding("UTF-8")) }
|
File.write("#{Rails.root}/tmp/#{self.class.to_s.underscore}.txt", to_csv.force_encoding("UTF-8"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,7 +34,7 @@ class RenderCSV
|
||||||
# Helper method to test pdf via rails console: OrderCsv.new(order).save_tmp
|
# Helper method to test pdf via rails console: OrderCsv.new(order).save_tmp
|
||||||
def save_tmp
|
def save_tmp
|
||||||
encoding = @options[:encoding] || 'UTF-8'
|
encoding = @options[:encoding] || 'UTF-8'
|
||||||
File.open("#{Rails.root}/tmp/#{self.class.to_s.underscore}.csv", 'w') { |f| f.write(to_csv.force_encoding(encoding)) }
|
File.write("#{Rails.root}/tmp/#{self.class.to_s.underscore}.csv", to_csv.force_encoding(encoding))
|
||||||
end
|
end
|
||||||
|
|
||||||
# XXX disable unit to avoid encoding problems, both in unit and whitespace. Also allows computations in spreadsheet.
|
# XXX disable unit to avoid encoding problems, both in unit and whitespace. Also allows computations in spreadsheet.
|
||||||
|
|
|
@ -120,7 +120,7 @@ class RenderPDF < Prawn::Document
|
||||||
|
|
||||||
# Helper method to test pdf via rails console: OrderByGroups.new(order).save_tmp
|
# Helper method to test pdf via rails console: OrderByGroups.new(order).save_tmp
|
||||||
def save_tmp
|
def save_tmp
|
||||||
File.open("#{Rails.root}/tmp/#{self.class.to_s.underscore}.pdf", 'w') { |f| f.write(to_pdf.force_encoding("UTF-8")) }
|
File.write("#{Rails.root}/tmp/#{self.class.to_s.underscore}.pdf", to_pdf.force_encoding("UTF-8"))
|
||||||
end
|
end
|
||||||
|
|
||||||
# @todo avoid underscore instead of unicode whitespace in pdf :/
|
# @todo avoid underscore instead of unicode whitespace in pdf :/
|
||||||
|
|
0
plugins/discourse/Rakefile
Normal file → Executable file
0
plugins/discourse/Rakefile
Normal file → Executable file
0
plugins/documents/Rakefile
Normal file → Executable file
0
plugins/documents/Rakefile
Normal file → Executable file
0
plugins/links/Rakefile
Normal file → Executable file
0
plugins/links/Rakefile
Normal file → Executable file
0
plugins/messages/Rakefile
Normal file → Executable file
0
plugins/messages/Rakefile
Normal file → Executable file
0
plugins/polls/Rakefile
Normal file → Executable file
0
plugins/polls/Rakefile
Normal file → Executable file
0
plugins/printer/Rakefile
Normal file → Executable file
0
plugins/printer/Rakefile
Normal file → Executable file
0
plugins/wiki/Rakefile
Normal file → Executable file
0
plugins/wiki/Rakefile
Normal file → Executable file
|
@ -2,7 +2,7 @@ module PagesHelper
|
||||||
include WikiCloth
|
include WikiCloth
|
||||||
|
|
||||||
def rss_meta_tag
|
def rss_meta_tag
|
||||||
tag('link', :rel => "alternate", :type => "application/rss+xml", :title => "RSS", :href => all_pages_rss_url).html_safe
|
tag.link(rel: "alternate", type: "application/rss+xml", title: "RSS", href: all_pages_rss_url).html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
def wikified_body(body, title = nil)
|
def wikified_body(body, title = nil)
|
||||||
|
|
|
@ -12,6 +12,7 @@ describe Api::V1::OrderArticlesController, type: :controller do
|
||||||
context "with param q[ordered]" do
|
context "with param q[ordered]" do
|
||||||
let(:order) { create(:order, article_count: 4) }
|
let(:order) { create(:order, article_count: 4) }
|
||||||
let(:order_articles) { order.order_articles }
|
let(:order_articles) { order.order_articles }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
order_articles[0].update_attributes! quantity: 0, tolerance: 0, units_to_order: 0
|
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
|
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
|
context "when ordered by user" do
|
||||||
let(:user) { create(:user, :ordergroup) }
|
let(:user) { create(:user, :ordergroup) }
|
||||||
let(:go) { create(:group_order, order: order, ordergroup: user.ordergroup) }
|
let(:go) { create(:group_order, order: order, ordergroup: user.ordergroup) }
|
||||||
|
|
||||||
before do
|
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[1], quantity: 1)
|
||||||
create(:group_order_article, group_order: go, order_article: order_articles[2], tolerance: 0)
|
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_2) { create :financial_transaction, ordergroup: user.ordergroup }
|
||||||
let!(:ft_3) { 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', 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}', 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' => 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}', 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
|
context 'without using self service' do
|
||||||
it { is_expected.to validate(:post, '/user/financial_transactions', 403, api_auth(create_params)) }
|
it { is_expected.to validate(:post, '/user/financial_transactions', 403, api_auth(create_params)) }
|
||||||
end
|
end
|
||||||
|
@ -83,6 +83,7 @@ describe 'API v1', type: :apivore, order: :defined do
|
||||||
|
|
||||||
context 'without enough balance' do
|
context 'without enough balance' do
|
||||||
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
||||||
|
|
||||||
it { is_expected.to validate(:post, '/user/financial_transactions', 403, api_auth(create_params)) }
|
it { is_expected.to validate(:post, '/user/financial_transactions', 403, api_auth(create_params)) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -100,6 +101,7 @@ describe 'API v1', type: :apivore, order: :defined do
|
||||||
let(:user_2) { create :user, :ordergroup }
|
let(:user_2) { create :user, :ordergroup }
|
||||||
let(:group_order_2) { create(:group_order, order: order, ordergroup: user_2.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 }
|
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! }
|
before { group_order_2.update_price!; user_2.ordergroup.update_stats! }
|
||||||
|
|
||||||
context 'without ordergroup' do
|
context 'without ordergroup' do
|
||||||
|
@ -109,8 +111,11 @@ describe 'API v1', type: :apivore, order: :defined do
|
||||||
|
|
||||||
context 'with ordergroup' do
|
context 'with ordergroup' do
|
||||||
let(:user) { create :user, :ordergroup }
|
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(: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 }
|
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! }
|
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', 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' => 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}', 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(: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(: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 })) }
|
||||||
|
@ -149,6 +151,7 @@ describe 'API v1', type: :apivore, order: :defined do
|
||||||
|
|
||||||
context 'without enough balance' do
|
context 'without enough balance' do
|
||||||
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
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(: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(: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 })) }
|
||||||
|
@ -156,6 +159,7 @@ describe 'API v1', type: :apivore, order: :defined do
|
||||||
|
|
||||||
context 'without enough apple points' do
|
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(: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(: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 })) }
|
||||||
|
@ -198,6 +202,7 @@ describe 'API v1', type: :apivore, order: :defined do
|
||||||
|
|
||||||
context 'without role_finance' do
|
context 'without role_finance' do
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
it { is_expected.to validate(:get, '/financial_transactions', 403, api_auth) }
|
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
|
end
|
||||||
|
|
|
@ -83,21 +83,25 @@ describe Api::V1::User::FinancialTransactionsController, type: :controller do
|
||||||
|
|
||||||
context "with existing financial transaction" do
|
context "with existing financial transaction" do
|
||||||
before { user.ordergroup.add_financial_transaction! 5000, 'for ordering', user, ftt3 }
|
before { user.ordergroup.add_financial_transaction! 5000, 'for ordering', user, ftt3 }
|
||||||
|
|
||||||
include_examples "financial_transactions create/update success"
|
include_examples "financial_transactions create/update success"
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with invalid financial transaction type" do
|
context "with invalid financial transaction type" do
|
||||||
let(:ft_params) { { amount: amount, financial_transaction_type_id: -1, note: note } }
|
let(:ft_params) { { amount: amount, financial_transaction_type_id: -1, note: note } }
|
||||||
|
|
||||||
include_examples "financial_transactions endpoint failure", 404
|
include_examples "financial_transactions endpoint failure", 404
|
||||||
end
|
end
|
||||||
|
|
||||||
context "without note" do
|
context "without note" do
|
||||||
let(:ft_params) { { amount: amount, financial_transaction_type_id: ftt1.id } }
|
let(:ft_params) { { amount: amount, financial_transaction_type_id: ftt1.id } }
|
||||||
|
|
||||||
include_examples "financial_transactions endpoint failure", 422
|
include_examples "financial_transactions endpoint failure", 422
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without enough balance' do
|
context 'without enough balance' do
|
||||||
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
||||||
|
|
||||||
include_examples "financial_transactions endpoint failure", 403
|
include_examples "financial_transactions endpoint failure", 403
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,8 @@ require 'spec_helper'
|
||||||
describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
||||||
include ApiOAuth
|
include ApiOAuth
|
||||||
let(:user) { create(:user, :ordergroup) }
|
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(:api_scopes) { ['group_orders:user'] }
|
||||||
|
|
||||||
let(:order) { create(:order, article_count: 1) }
|
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(: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) }
|
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'] }
|
before { go_other.update_price!; user_other.ordergroup.update_stats! }
|
||||||
let(:json_oa) { json_response['order_article'] }
|
|
||||||
|
|
||||||
shared_examples "group_order_articles endpoint success" do
|
shared_examples "group_order_articles endpoint success" do
|
||||||
before { request }
|
before { request }
|
||||||
|
@ -95,47 +95,54 @@ describe Api::V1::User::GroupOrderArticlesController, type: :controller do
|
||||||
|
|
||||||
context "with an existing group_order" do
|
context "with an existing group_order" do
|
||||||
let!(:go) { create(:group_order, order: order, ordergroup: user.ordergroup) }
|
let!(:go) { create(:group_order, order: order, ordergroup: user.ordergroup) }
|
||||||
|
|
||||||
include_examples "group_order_articles create/update success"
|
include_examples "group_order_articles create/update success"
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with an existing group_order_article" do
|
context "with an existing group_order_article" do
|
||||||
let!(:go) { create(:group_order, order: order, ordergroup: user.ordergroup) }
|
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) }
|
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! }
|
before { go.update_price!; user.ordergroup.update_stats! }
|
||||||
|
|
||||||
include_examples "group_order_articles endpoint failure", 422
|
include_examples "group_order_articles endpoint failure", 422
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with invalid parameter values" do
|
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
|
include_examples "group_order_articles endpoint failure", 422
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a closed order' do
|
context 'with a closed order' do
|
||||||
let(:order) { create(:order, article_count: 1, state: :finished) }
|
let(:order) { create(:order, article_count: 1, state: :finished) }
|
||||||
|
|
||||||
include_examples "group_order_articles endpoint failure", 404
|
include_examples "group_order_articles endpoint failure", 404
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without enough balance' do
|
context 'without enough balance' do
|
||||||
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
||||||
|
|
||||||
include_examples "group_order_articles endpoint failure", 403
|
include_examples "group_order_articles endpoint failure", 403
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without enough apple points' do
|
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
|
include_examples "group_order_articles endpoint failure", 403
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "PATCH :update" do
|
describe "PATCH :update" do
|
||||||
let(:new_quantity) { rand(2..10) }
|
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(:new_tolerance) { rand(2..10) }
|
||||||
|
|
||||||
let!(:go) { create(:group_order, order: order, ordergroup: user.ordergroup) }
|
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) }
|
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 } }
|
before { go.update_price!; user.ordergroup.update_stats! }
|
||||||
let(:request) { patch :update, params: { id: goa.id, group_order_article: goa_params, foodcoop: 'f' } }
|
|
||||||
|
|
||||||
context "happy flow" do
|
context "happy flow" do
|
||||||
include_examples "group_order_articles create/update success"
|
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
|
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
|
include_examples "group_order_articles endpoint failure", 422
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a closed order' do
|
context 'with a closed order' do
|
||||||
let(:order) { create(:order, article_count: 1, state: :finished) }
|
let(:order) { create(:order, article_count: 1, state: :finished) }
|
||||||
|
|
||||||
include_examples "group_order_articles endpoint failure", 404
|
include_examples "group_order_articles endpoint failure", 404
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without enough balance' do
|
context 'without enough balance' do
|
||||||
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
||||||
|
|
||||||
include_examples "group_order_articles endpoint failure", 403
|
include_examples "group_order_articles endpoint failure", 403
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without enough apple points' do
|
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
|
include_examples "group_order_articles endpoint failure", 403
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "DELETE :destroy" do
|
describe "DELETE :destroy" do
|
||||||
let(:new_quantity) { 0 }
|
let(:new_quantity) { 0 }
|
||||||
|
let(:request) { delete :destroy, params: { id: goa.id, foodcoop: 'f' } }
|
||||||
let(:new_tolerance) { 0 }
|
let(:new_tolerance) { 0 }
|
||||||
|
|
||||||
let!(:go) { create(:group_order, order: order, ordergroup: user.ordergroup) }
|
let!(:go) { create(:group_order, order: order, ordergroup: user.ordergroup) }
|
||||||
let!(:goa) { create(:group_order_article, group_order: go, order_article: oa_1) }
|
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
|
shared_examples "group_order_articles destroy success" do
|
||||||
include_examples "group_order_articles endpoint success"
|
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
|
context 'with a closed order' do
|
||||||
let(:order) { create(:order, article_count: 1, state: :finished) }
|
let(:order) { create(:order, article_count: 1, state: :finished) }
|
||||||
|
|
||||||
include_examples "group_order_articles endpoint failure", 404
|
include_examples "group_order_articles endpoint failure", 404
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without enough balance' do
|
context 'without enough balance' do
|
||||||
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
before { FoodsoftConfig[:minimum_balance] = 1000 }
|
||||||
|
|
||||||
include_examples "group_order_articles destroy success"
|
include_examples "group_order_articles destroy success"
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without enough apple points' do
|
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"
|
include_examples "group_order_articles destroy success"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,13 +13,13 @@ describe Api::V1::User::OrdergroupController, type: :controller do
|
||||||
|
|
||||||
describe "GET :financial_overview" do
|
describe "GET :financial_overview" do
|
||||||
let(:order) { create(:order, article_count: 1) }
|
let(:order) { create(:order, article_count: 1) }
|
||||||
|
let(:json_financial_overview) { json_response['financial_overview'] }
|
||||||
let(:oa_1) { order.order_articles.first }
|
let(:oa_1) { order.order_articles.first }
|
||||||
|
|
||||||
let!(:go) { create(:group_order, order: order, ordergroup: user.ordergroup) }
|
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) }
|
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
|
before do
|
||||||
og = user.ordergroup
|
og = user.ordergroup
|
||||||
|
|
|
@ -14,13 +14,13 @@ FactoryBot.define do
|
||||||
article_category
|
article_category
|
||||||
end
|
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}" }
|
sequence(:name) { |n| Faker::Lorem.words(number: rand(2..4)).join(' ') + " s##{n}" }
|
||||||
order_number { Faker::Lorem.characters(number: rand(1..12)) }
|
order_number { Faker::Lorem.characters(number: rand(1..12)) }
|
||||||
shared_supplier
|
shared_supplier
|
||||||
end
|
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}" }
|
sequence(:name) { |n| Faker::Lorem.words(number: rand(2..4)).join(' ') + " ##{n}" }
|
||||||
unit_quantity { 1 }
|
unit_quantity { 1 }
|
||||||
supplier
|
supplier
|
||||||
|
|
|
@ -2,12 +2,12 @@ require 'factory_bot'
|
||||||
require 'doorkeeper'
|
require 'doorkeeper'
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :oauth2_application, class: Doorkeeper::Application do
|
factory :oauth2_application, class: 'Doorkeeper::Application' do
|
||||||
name { Faker::App.name }
|
name { Faker::App.name }
|
||||||
redirect_uri { 'https://example.com:1234/app' }
|
redirect_uri { 'https://example.com:1234/app' }
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :oauth2_access_token, class: Doorkeeper::AccessToken do
|
factory :oauth2_access_token, class: 'Doorkeeper::AccessToken' do
|
||||||
application factory: :oauth2_application
|
application factory: :oauth2_application
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,7 @@ FactoryBot.define do
|
||||||
create_list :article, article_count, supplier: supplier
|
create_list :article, article_count, supplier: supplier
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :shared_supplier, class: SharedSupplier
|
factory :shared_supplier, class: 'SharedSupplier'
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :supplier_category do
|
factory :supplier_category do
|
||||||
|
|
|
@ -4,6 +4,7 @@ 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(:supplier) { create :supplier }
|
||||||
let!(:article_category) { create :article_category }
|
let!(:article_category) { create :article_category }
|
||||||
|
|
||||||
before { login user }
|
before { login user }
|
||||||
|
|
||||||
describe ':index', js: true do
|
describe ':index', js: true do
|
||||||
|
@ -17,7 +18,7 @@ feature ArticlesController do
|
||||||
it 'can create a new article' do
|
it 'can create a new article' do
|
||||||
click_on I18n.t('articles.index.new')
|
click_on I18n.t('articles.index.new')
|
||||||
expect(page).to have_selector('form#new_article')
|
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
|
within('#new_article') do
|
||||||
fill_in 'article_name', :with => article.name
|
fill_in 'article_name', :with => article.name
|
||||||
fill_in 'article_unit', :with => article.unit
|
fill_in 'article_unit', :with => article.unit
|
||||||
|
@ -37,6 +38,7 @@ feature ArticlesController do
|
||||||
describe ':upload' do
|
describe ':upload' do
|
||||||
let(:filename) { 'foodsoft_file_02.csv' }
|
let(:filename) { 'foodsoft_file_02.csv' }
|
||||||
let(:file) { Rails.root.join("spec/fixtures/#{filename}") }
|
let(:file) { Rails.root.join("spec/fixtures/#{filename}") }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
visit upload_supplier_articles_path(supplier_id: supplier.id)
|
visit upload_supplier_articles_path(supplier_id: supplier.id)
|
||||||
attach_file 'articles_file', file
|
attach_file 'articles_file', file
|
||||||
|
@ -45,6 +47,7 @@ feature ArticlesController do
|
||||||
Dir.glob('spec/fixtures/foodsoft_file_01.*') do |test_file|
|
Dir.glob('spec/fixtures/foodsoft_file_01.*') do |test_file|
|
||||||
describe "can import articles from #{test_file}" do
|
describe "can import articles from #{test_file}" do
|
||||||
let(:file) { Rails.root.join(test_file) }
|
let(:file) { Rails.root.join(test_file) }
|
||||||
|
|
||||||
it do
|
it do
|
||||||
find('input[type="submit"]').click
|
find('input[type="submit"]').click
|
||||||
expect(find("tr:nth-child(1) #new_articles__note").value).to eq "bio ◎"
|
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
|
describe "can update existing article" do
|
||||||
let!(:article) { create :article, supplier: supplier, name: 'Foobar', order_number: 1, unit: '250 g' }
|
let!(:article) { create :article, supplier: supplier, name: 'Foobar', order_number: 1, unit: '250 g' }
|
||||||
|
|
||||||
it do
|
it do
|
||||||
find('input[type="submit"]').click
|
find('input[type="submit"]').click
|
||||||
expect(find("#articles_#{article.id}_name").value).to eq 'Tomatoes'
|
expect(find("#articles_#{article.id}_name").value).to eq 'Tomatoes'
|
||||||
|
@ -88,6 +92,7 @@ feature ArticlesController do
|
||||||
|
|
||||||
describe "can remove an existing article" do
|
describe "can remove an existing article" do
|
||||||
let!(:article) { create :article, supplier: supplier, name: 'Foobar', order_number: 99999 }
|
let!(:article) { create :article, supplier: supplier, name: 'Foobar', order_number: 99999 }
|
||||||
|
|
||||||
it do
|
it do
|
||||||
check('articles_outlist_absent')
|
check('articles_outlist_absent')
|
||||||
find('input[type="submit"]').click
|
find('input[type="submit"]').click
|
||||||
|
@ -101,6 +106,7 @@ feature ArticlesController do
|
||||||
|
|
||||||
describe "can convert units when updating" do
|
describe "can convert units when updating" do
|
||||||
let!(:article) { create :article, supplier: supplier, order_number: 1, unit: '250 g' }
|
let!(:article) { create :article, supplier: supplier, order_number: 1, unit: '250 g' }
|
||||||
|
|
||||||
it do
|
it do
|
||||||
check('articles_convert_units')
|
check('articles_convert_units')
|
||||||
find('input[type="submit"]').click
|
find('input[type="submit"]').click
|
||||||
|
|
|
@ -12,6 +12,7 @@ feature 'settling an order', js: true do
|
||||||
let(:oa) { order.order_articles.find_by_article_id(article.id) }
|
let(:oa) { order.order_articles.find_by_article_id(article.id) }
|
||||||
let(:goa1) { create :group_order_article, group_order: go1, order_article: oa }
|
let(:goa1) { create :group_order_article, group_order: go1, order_article: oa }
|
||||||
let(:goa2) { create :group_order_article, group_order: go2, order_article: oa }
|
let(:goa2) { create :group_order_article, group_order: go2, order_article: oa }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
goa1.update_quantities(3, 0)
|
goa1.update_quantities(3, 0)
|
||||||
goa2.update_quantities(1, 0)
|
goa2.update_quantities(1, 0)
|
||||||
|
@ -29,6 +30,7 @@ feature 'settling an order', js: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
before { login admin }
|
before { login admin }
|
||||||
|
|
||||||
before { visit new_finance_order_path(order_id: order.id) }
|
before { visit new_finance_order_path(order_id: order.id) }
|
||||||
|
|
||||||
it 'has product ordered visible' do
|
it 'has product ordered visible' do
|
||||||
|
|
|
@ -5,6 +5,7 @@ feature LoginController do
|
||||||
|
|
||||||
describe 'forgot password' do
|
describe 'forgot password' do
|
||||||
before { visit forgot_password_path }
|
before { visit forgot_password_path }
|
||||||
|
|
||||||
it 'is accessible' do
|
it 'is accessible' do
|
||||||
expect(page).to have_selector 'input[id=user_email]'
|
expect(page).to have_selector 'input[id=user_email]'
|
||||||
end
|
end
|
||||||
|
@ -21,7 +22,9 @@ feature LoginController do
|
||||||
describe 'and reset it' do
|
describe 'and reset it' do
|
||||||
let(:token) { user.reset_password_token }
|
let(:token) { user.reset_password_token }
|
||||||
let(:newpass) { user.new_random_password }
|
let(:newpass) { user.new_random_password }
|
||||||
|
|
||||||
before { user.request_password_reset! }
|
before { user.request_password_reset! }
|
||||||
|
|
||||||
before { visit new_password_path(id: user.id, token: token) }
|
before { visit new_password_path(id: user.id, token: token) }
|
||||||
|
|
||||||
it 'is accessible' do
|
it 'is accessible' do
|
||||||
|
@ -30,6 +33,7 @@ feature LoginController do
|
||||||
|
|
||||||
describe 'with wrong token' do
|
describe 'with wrong token' do
|
||||||
let(:token) { 'foobar' }
|
let(:token) { 'foobar' }
|
||||||
|
|
||||||
it 'is not accessible' do
|
it 'is not accessible' do
|
||||||
expect(page).to have_selector '.alert-error'
|
expect(page).to have_selector '.alert-error'
|
||||||
expect(page).to_not have_selector 'input[type=password]'
|
expect(page).to_not have_selector 'input[type=password]'
|
||||||
|
|
|
@ -8,14 +8,17 @@ feature 'the session' do
|
||||||
visit login_path
|
visit login_path
|
||||||
expect(page).to have_selector('input[type=password]')
|
expect(page).to have_selector('input[type=password]')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'logs me in' do
|
it 'logs me in' do
|
||||||
login user
|
login user
|
||||||
expect(page).to_not have_selector('.alert-error')
|
expect(page).to_not have_selector('.alert-error')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not log me in with wrong password' do
|
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')
|
expect(page).to have_selector('.alert-error')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can log me in using an email address' do
|
it 'can log me in using an email address' do
|
||||||
visit login_path
|
visit login_path
|
||||||
fill_in 'nick', :with => user.email
|
fill_in 'nick', :with => user.email
|
||||||
|
|
|
@ -5,6 +5,7 @@ feature 'supplier' do
|
||||||
|
|
||||||
describe 'create new' do
|
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 }
|
before { login user }
|
||||||
|
|
||||||
it 'can be created' do
|
it 'can be created' do
|
||||||
|
|
|
@ -5,7 +5,7 @@ describe Article do
|
||||||
let(:article) { create :article, supplier: supplier }
|
let(:article) { create :article, supplier: supplier }
|
||||||
|
|
||||||
it 'has a unique name' do
|
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
|
expect(article2).to be_invalid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,7 @@ describe OrderArticle do
|
||||||
|
|
||||||
describe 'boxfill' do
|
describe 'boxfill' do
|
||||||
before { FoodsoftConfig[:use_boxfill] = true }
|
before { FoodsoftConfig[:use_boxfill] = true }
|
||||||
|
|
||||||
let(:article) { create :article, unit_quantity: 6 }
|
let(:article) { create :article, unit_quantity: 6 }
|
||||||
let(:order) { create :order, article_ids: [article.id], starts: 1.week.ago }
|
let(:order) { create :order, article_ids: [article.id], starts: 1.week.ago }
|
||||||
let(:oa) { order.order_articles.first }
|
let(:oa) { order.order_articles.first }
|
||||||
|
@ -139,7 +140,7 @@ describe OrderArticle do
|
||||||
shared_examples "boxfill" do |success, q|
|
shared_examples "boxfill" do |success, q|
|
||||||
# initial situation
|
# initial situation
|
||||||
before do
|
before do
|
||||||
goa.update_quantities *q.keys[0]
|
goa.update_quantities(*q.keys[0])
|
||||||
oa.update_results!; oa.reload
|
oa.update_results!; oa.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -153,7 +154,7 @@ describe OrderArticle do
|
||||||
order.update_attributes(boxfill: boxfill_from)
|
order.update_attributes(boxfill: boxfill_from)
|
||||||
|
|
||||||
r = proc {
|
r = proc {
|
||||||
goa.update_quantities *q.values[0]
|
goa.update_quantities(*q.values[0])
|
||||||
oa.update_results!
|
oa.update_results!
|
||||||
}
|
}
|
||||||
if success
|
if success
|
||||||
|
@ -169,9 +170,11 @@ describe OrderArticle do
|
||||||
|
|
||||||
context 'before the date' do
|
context 'before the date' do
|
||||||
let(:boxfill_from) { 1.hour.from_now }
|
let(:boxfill_from) { 1.hour.from_now }
|
||||||
|
|
||||||
context 'decreasing the missing units' do
|
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
|
end
|
||||||
|
|
||||||
context 'decreasing the tolerance' do
|
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
|
||||||
|
@ -179,21 +182,27 @@ describe OrderArticle do
|
||||||
|
|
||||||
context 'after the date' do
|
context 'after the date' do
|
||||||
let(:boxfill_from) { 1.second.ago }
|
let(:boxfill_from) { 1.second.ago }
|
||||||
|
|
||||||
context 'changing nothing in particular' do
|
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
|
end
|
||||||
|
|
||||||
context 'increasing missing units' do
|
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
|
end
|
||||||
|
|
||||||
context 'increasing tolerance' do
|
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
|
end
|
||||||
|
|
||||||
context 'decreasing quantity to fix missing units' do
|
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
|
end
|
||||||
|
|
||||||
context 'decreasing quantity keeping missing units equal' do
|
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
|
end
|
||||||
|
|
||||||
context 'moving tolerance to quantity' do
|
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
|
end
|
||||||
|
|
|
@ -24,46 +24,46 @@ describe Order do
|
||||||
let!(:received_order) { create :order, state: 'received' }
|
let!(:received_order) { create :order, state: 'received' }
|
||||||
let!(:closed_order) { create :order, state: 'closed' }
|
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.count).to eq(1)
|
||||||
expect(Order.open.where(id: open_order.id)).to exist
|
expect(Order.open.where(id: open_order.id)).to exist
|
||||||
end
|
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.count).to eq(3)
|
||||||
expect(Order.finished.where(id: finished_order.id)).to exist
|
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: received_order.id)).to exist
|
||||||
expect(Order.finished.where(id: closed_order.id)).to exist
|
expect(Order.finished.where(id: closed_order.id)).to exist
|
||||||
end
|
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.count).to eq(2)
|
||||||
expect(Order.finished_not_closed.where(id: finished_order.id)).to exist
|
expect(Order.finished_not_closed.where(id: finished_order.id)).to exist
|
||||||
expect(Order.finished_not_closed.where(id: received_order.id)).to exist
|
expect(Order.finished_not_closed.where(id: received_order.id)).to exist
|
||||||
end
|
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.open?).to be(true)
|
||||||
expect(open_order.finished?).to be(false)
|
expect(open_order.finished?).to be(false)
|
||||||
expect(open_order.received?).to be(false)
|
expect(open_order.received?).to be(false)
|
||||||
expect(open_order.closed?).to be(false)
|
expect(open_order.closed?).to be(false)
|
||||||
end
|
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.open?).to be(false)
|
||||||
expect(finished_order.finished?).to be(true)
|
expect(finished_order.finished?).to be(true)
|
||||||
expect(finished_order.received?).to be(false)
|
expect(finished_order.received?).to be(false)
|
||||||
expect(finished_order.closed?).to be(false)
|
expect(finished_order.closed?).to be(false)
|
||||||
end
|
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.open?).to be(false)
|
||||||
expect(received_order.finished?).to be(true)
|
expect(received_order.finished?).to be(true)
|
||||||
expect(received_order.received?).to be(true)
|
expect(received_order.received?).to be(true)
|
||||||
expect(received_order.closed?).to be(false)
|
expect(received_order.closed?).to be(false)
|
||||||
end
|
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.open?).to be(false)
|
||||||
expect(closed_order.finished?).to be(false)
|
expect(closed_order.finished?).to be(false)
|
||||||
expect(closed_order.received?).to be(false)
|
expect(closed_order.received?).to be(false)
|
||||||
|
@ -122,6 +122,7 @@ describe Order do
|
||||||
|
|
||||||
describe 'with a default end date' do
|
describe 'with a default end date' do
|
||||||
let(:order) { create :order }
|
let(:order) { create :order }
|
||||||
|
|
||||||
before do
|
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
|
order.init_dates
|
||||||
|
|
|
@ -15,6 +15,7 @@ describe User do
|
||||||
|
|
||||||
describe 'does not have the role' do
|
describe 'does not have the role' do
|
||||||
let(:user) { create :user }
|
let(:user) { create :user }
|
||||||
|
|
||||||
it 'admin' do expect(user.role_admin?).to be_falsey end
|
it 'admin' do expect(user.role_admin?).to be_falsey end
|
||||||
it 'finance' do expect(user.role_finance?).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
|
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
|
it 'can authenticate with correct password' do
|
||||||
expect(User.authenticate(user.nick, 'blahblahblah')).to be_truthy
|
expect(User.authenticate(user.nick, 'blahblahblah')).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can not authenticate with incorrect password' do
|
it 'can not authenticate with incorrect password' do
|
||||||
expect(User.authenticate(user.nick, 'foobar')).to be_nil
|
expect(User.authenticate(user.nick, 'foobar')).to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can not authenticate with nil nick' do
|
it 'can not authenticate with nil nick' do
|
||||||
expect(User.authenticate(nil, 'blahblahblah')).to be_nil
|
expect(User.authenticate(nil, 'blahblahblah')).to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can not authenticate with nil password' do
|
it 'can not authenticate with nil password' do
|
||||||
expect(User.authenticate(user.nick, nil)).to be_nil
|
expect(User.authenticate(user.nick, nil)).to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can not set a password without matching confirmation' do
|
it 'can not set a password without matching confirmation' do
|
||||||
user.password = 'abcdefghijkl'
|
user.password = 'abcdefghijkl'
|
||||||
user.password_confirmation = 'foobaruvwxyz'
|
user.password_confirmation = 'foobaruvwxyz'
|
||||||
expect(user).to be_invalid
|
expect(user).to be_invalid
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can set a password with matching confirmation' do
|
it 'can set a password with matching confirmation' do
|
||||||
user.password = 'abcdefghijkl'
|
user.password = 'abcdefghijkl'
|
||||||
user.password_confirmation = 'abcdefghijkl'
|
user.password_confirmation = 'abcdefghijkl'
|
||||||
|
@ -51,6 +57,7 @@ describe User do
|
||||||
it 'has a unique nick' do
|
it 'has a unique nick' do
|
||||||
expect(build(:user, nick: user.nick, email: "x-#{user.email}")).to be_invalid
|
expect(build(:user, nick: user.nick, email: "x-#{user.email}")).to be_invalid
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has a unique email' do
|
it 'has a unique email' do
|
||||||
expect(build(:user, email: "#{user.email}")).to be_invalid
|
expect(build(:user, email: "#{user.email}")).to be_invalid
|
||||||
end
|
end
|
||||||
|
@ -68,6 +75,7 @@ describe User do
|
||||||
|
|
||||||
describe 'admin' do
|
describe 'admin' do
|
||||||
let(:user) { create :admin }
|
let(:user) { create :admin }
|
||||||
|
|
||||||
it 'default admin role' do expect(user.role_admin?).to be_truthy end
|
it 'default admin role' do expect(user.role_admin?).to be_truthy end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,7 @@ module ApiHelper
|
||||||
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
|
context 'with invalid access token' do
|
||||||
let(:api_access_token) { 'abc' }
|
let(:api_access_token) { 'abc' }
|
||||||
|
|
||||||
it { is_expected.to validate(method, path, 401, instance_exec(¶ms_block)) }
|
it { is_expected.to validate(method, path, 401, instance_exec(¶ms_block)) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,6 +18,7 @@ module ApiHelper
|
||||||
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
|
context 'with invalid scope' do
|
||||||
let(:api_scopes) { ['none'] }
|
let(:api_scopes) { ['none'] }
|
||||||
|
|
||||||
it { is_expected.to validate(method, path, 403, instance_exec(¶ms_block)) }
|
it { is_expected.to validate(method, path, 403, instance_exec(¶ms_block)) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,7 @@ module ApiOAuth
|
||||||
let(:api_scopes) { [] } # empty scopes for stricter testing (in reality this would be default_scopes)
|
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) }
|
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(:doorkeeper_token) { api_access_token } }
|
||||||
|
|
||||||
before { allow(controller).to receive(:current_user) { user } }
|
before { allow(controller).to receive(:current_user) { user } }
|
||||||
|
|
||||||
let(:json_response) { JSON.parse(response.body) }
|
let(:json_response) { JSON.parse(response.body) }
|
||||||
|
|
Loading…
Reference in a new issue