diff --git a/.gitignore b/.gitignore index 5668cba6..ad72dcbe 100755 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,5 @@ log/*.yml salor-hospitality/.DS_Store salor-hospitality/config/.DS_Store .DS_Store +salor-hospitality/.ruby-version +salor-hospitality/.ruby-gemset diff --git a/salor-hospitality/.rspec b/salor-hospitality/.rspec index 53607ea5..83e16f80 100755 --- a/salor-hospitality/.rspec +++ b/salor-hospitality/.rspec @@ -1 +1,2 @@ ---colour +--color +--require spec_helper diff --git a/salor-hospitality/Gemfile b/salor-hospitality/Gemfile index 3e822c9f..7531859d 100755 --- a/salor-hospitality/Gemfile +++ b/salor-hospitality/Gemfile @@ -2,7 +2,7 @@ source 'http://rubygems.org' ruby '2.1.5' -gem 'rails', '4.1.8' +gem 'rails', '~> 4.1' gem 'rake', '10.3.2' gem 'rack', '1.5.2' gem 'kramdown', '1.4.2' @@ -20,6 +20,18 @@ gem 'rubyzip', '0.9.9' gem 'therubyracer', '0.12.2' -group :development do +group :development, :test do gem 'byebug' + gem 'rspec-rails' + gem 'pry-rails' + gem 'pry-nav' + gem 'pry-stack_explorer' + gem 'faker' +end + +group :test do + gem 'database_cleaner' + gem 'factory_girl_rails', '~> 4.0' + gem 'shoulda-matchers' + gem 'chronic' end \ No newline at end of file diff --git a/salor-hospitality/Gemfile.lock b/salor-hospitality/Gemfile.lock index 5b6a11a8..7c394200 100755 --- a/salor-hospitality/Gemfile.lock +++ b/salor-hospitality/Gemfile.lock @@ -1,36 +1,40 @@ GEM remote: http://rubygems.org/ specs: - actionmailer (4.1.8) - actionpack (= 4.1.8) - actionview (= 4.1.8) + actionmailer (4.1.14) + actionpack (= 4.1.14) + actionview (= 4.1.14) mail (~> 2.5, >= 2.5.4) - actionpack (4.1.8) - actionview (= 4.1.8) - activesupport (= 4.1.8) + actionpack (4.1.14) + actionview (= 4.1.14) + activesupport (= 4.1.14) rack (~> 1.5.2) rack-test (~> 0.6.2) - actionview (4.1.8) - activesupport (= 4.1.8) + actionview (4.1.14) + activesupport (= 4.1.14) builder (~> 3.1) erubis (~> 2.7.0) - activemodel (4.1.8) - activesupport (= 4.1.8) + activemodel (4.1.14) + activesupport (= 4.1.14) builder (~> 3.1) - activerecord (4.1.8) - activemodel (= 4.1.8) - activesupport (= 4.1.8) + activerecord (4.1.14) + activemodel (= 4.1.14) + activesupport (= 4.1.14) arel (~> 5.0.0) - activesupport (4.1.8) + activesupport (4.1.14) i18n (~> 0.6, >= 0.6.9) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.1) tzinfo (~> 1.1) arel (5.0.1.20140414130214) + binding_of_caller (0.7.2) + debug_inspector (>= 0.0.1) builder (3.2.2) byebug (5.0.0) columnize (= 0.9.0) + chronic (0.10.2) + coderay (1.1.0) coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -39,8 +43,18 @@ GEM execjs coffee-script-source (1.9.1.1) columnize (0.9.0) + database_cleaner (1.5.1) + debug_inspector (0.0.2) + diff-lcs (1.2.5) erubis (2.7.0) execjs (2.5.2) + factory_girl (4.5.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.5.0) + factory_girl (~> 4.5.0) + railties (>= 3.0.0) + faker (1.6.1) + i18n (~> 0.5) haml (4.0.5) tilt hike (1.2.3) @@ -50,36 +64,65 @@ GEM thor (>= 0.14, < 2.0) jquery-ui-rails (4.2.0) railties (>= 3.2.16) - json (1.8.2) + json (1.8.3) kramdown (1.4.2) libv8 (3.16.14.13) mail (2.6.3) mime-types (>= 1.16, < 3) - mime-types (2.5) - minitest (5.6.1) - multi_json (1.11.0) + method_source (0.8.2) + mime-types (2.99) + minitest (5.8.3) + multi_json (1.11.2) mysql2 (0.3.16) + pry (0.10.3) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry-nav (0.2.4) + pry (>= 0.9.10, < 0.11.0) + pry-rails (0.3.4) + pry (>= 0.9.10) + pry-stack_explorer (0.4.9.2) + binding_of_caller (>= 0.7) + pry (>= 0.9.11) rack (1.5.2) rack-test (0.6.3) rack (>= 1.0) - rails (4.1.8) - actionmailer (= 4.1.8) - actionpack (= 4.1.8) - actionview (= 4.1.8) - activemodel (= 4.1.8) - activerecord (= 4.1.8) - activesupport (= 4.1.8) + rails (4.1.14) + actionmailer (= 4.1.14) + actionpack (= 4.1.14) + actionview (= 4.1.14) + activemodel (= 4.1.14) + activerecord (= 4.1.14) + activesupport (= 4.1.14) bundler (>= 1.3.0, < 2.0) - railties (= 4.1.8) + railties (= 4.1.14) sprockets-rails (~> 2.0) - railties (4.1.8) - actionpack (= 4.1.8) - activesupport (= 4.1.8) + railties (4.1.14) + actionpack (= 4.1.14) + activesupport (= 4.1.14) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.3.2) ref (2.0.0) rmagick (2.15.0) + rspec-core (3.4.1) + rspec-support (~> 3.4.0) + rspec-expectations (3.4.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-mocks (3.4.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-rails (3.4.0) + actionpack (>= 3.0, < 4.3) + activesupport (>= 3.0, < 4.3) + railties (>= 3.0, < 4.3) + rspec-core (~> 3.4.0) + rspec-expectations (~> 3.4.0) + rspec-mocks (~> 3.4.0) + rspec-support (~> 3.4.0) + rspec-support (3.4.1) rubyzip (0.9.9) sass (3.2.19) sass-rails (4.0.3) @@ -88,12 +131,15 @@ GEM sprockets (~> 2.8, <= 2.11.0) sprockets-rails (~> 2.0) serialport (1.3.0) + shoulda-matchers (3.0.1) + activesupport (>= 4.0.0) + slop (3.6.0) sprockets (2.11.0) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.3.1) + sprockets-rails (2.3.3) actionpack (>= 3.0) activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) @@ -114,19 +160,28 @@ PLATFORMS DEPENDENCIES byebug + chronic coffee-rails (= 4.0.1) + database_cleaner + factory_girl_rails (~> 4.0) + faker haml (= 4.0.5) jquery-rails (= 3.1.2) jquery-ui-rails (= 4.2.0) kramdown (= 1.4.2) mysql2 (= 0.3.16) + pry-nav + pry-rails + pry-stack_explorer rack (= 1.5.2) - rails (= 4.1.8) + rails (~> 4.1) rake (= 10.3.2) rmagick (= 2.15.0) + rspec-rails rubyzip (= 0.9.9) sass-rails (= 4.0.3) serialport (= 1.3.0) + shoulda-matchers sprockets (= 2.11.0) therubyracer (= 0.12.2) uglifier (= 2.5.3) diff --git a/salor-hospitality/app/models/season.rb b/salor-hospitality/app/models/season.rb index d2e0dd19..1e5f7107 100755 --- a/salor-hospitality/app/models/season.rb +++ b/salor-hospitality/app/models/season.rb @@ -9,7 +9,7 @@ class Season < ActiveRecord::Base include Scope include Base - + belongs_to :vendor belongs_to :company has_many :surcharges @@ -22,15 +22,15 @@ class Season < ActiveRecord::Base def self.current(vendor) now = Time.now - current_season = Season.where("(MONTH(from_date)<#{now.month} OR (MONTH(from_date) = #{now.month} AND DAY(from_date) <= #{now.day})) AND (MONTH(to_date) > #{now.month} OR (MONTH(to_date) = #{now.month} AND DAY(to_date) > #{now.day})) AND vendor_id = #{vendor.id}").order('duration ASC').first + current_season = Season.where("from_date < ?",now).where("to_date > ?",now).where(vendor_id:vendor.id).order('duration ASC').first end def from_date=(from) - write_attribute :from_date, Time.parse("#{ Time.now.year.to_s }-" + from.strftime("%m-%d")).beginning_of_day + write_attribute :from_date, Time.parse("#{from.strftime("%Y")}-" + from.strftime("%m-%d")).beginning_of_day end def to_date=(to) - write_attribute :to_date, Time.parse("#{ Time.now.year.to_s }-" + to.strftime("%m-%d")).end_of_day + write_attribute :to_date, Time.parse("#{to.strftime("%Y")}-" + to.strftime("%m-%d")).end_of_day end def calculate_duration diff --git a/salor-hospitality/spec/factories/season_factory.rb b/salor-hospitality/spec/factories/season_factory.rb new file mode 100644 index 00000000..1f77e4e2 --- /dev/null +++ b/salor-hospitality/spec/factories/season_factory.rb @@ -0,0 +1,32 @@ +FactoryGirl.define do + factory :season do + company_id 1 + vendor_id 1 + color "#d6c951" + + trait :spring do + name "Spring" + from_date Date.parse('2015-03-21') + to_date Date.parse('2015-06-19') + end + + trait :summer do + name "Summer" + from_date Date.parse('2014-06-20') + to_date Date.parse('2014-09-19') + end + + trait :autumn do + name "Autumn" + from_date Date.parse('2014-09-20') + to_date Date.parse('2014-12-20') + end + + trait :winter do + name "Winter" + from_date Date.parse('2014-12-21') + to_date Date.parse('2015-03-20') + end + + end +end diff --git a/salor-hospitality/spec/models/receipt_spec.rb b/salor-hospitality/spec/models/receipt_spec.rb new file mode 100644 index 00000000..e0b3bf01 --- /dev/null +++ b/salor-hospitality/spec/models/receipt_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +describe Receipt do + context "content" do + it "accepts null byte in content" do + expect { Receipt.new(content:"\e@\e!8\n\n\n\n\n21:12:23 # 5\nSuperuser 0 T000\n—————————————————————\n 1 Article0050 \n\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4\xC4 16,00\n\n\n\n\n\n\n\u001DV\u0000") }.not_to raise_error + end + end +end diff --git a/salor-hospitality/spec/models/season_spec.rb b/salor-hospitality/spec/models/season_spec.rb new file mode 100644 index 00000000..f1e6e8b6 --- /dev/null +++ b/salor-hospitality/spec/models/season_spec.rb @@ -0,0 +1,40 @@ +require 'rails_helper' +describe Season do + context "#current" do + before(:each) do + %w{spring summer autumn winter}.each do |season| + FactoryGirl.create(:season,season.to_sym) + end + end + context "autumn" do + it "returns autumn" do + travel_to Chronic.parse("2014-10-21") do + expect(Season.current(Vendor.new(id:1)).name).to eq("Autumn") + end + end + it "returns autumn for start date" do + travel_to Chronic.parse("2014-09-20") do + expect(Season.current(Vendor.new(id:1)).name).to eq("Autumn") + end + end + it "returns autumn for end date" do + travel_to Chronic.parse("2014-12-20") do + expect(Season.current(Vendor.new(id:1)).name).to eq("Autumn") + end + end + end + context "winter" do + it "returns Winter for start date" do + travel_to Chronic.parse("2014-12-21") do + expect(Season.current(Vendor.new(id:1)).name).to eq("Winter") + end + end + it "returns Winter for end date" do + travel_to Chronic.parse("2015-03-20") do + expect(Season.current(Vendor.new(id:1)).name).to eq("Winter") + end + end + + end + end +end diff --git a/salor-hospitality/spec/rails_helper.rb b/salor-hospitality/spec/rails_helper.rb new file mode 100644 index 00000000..43ce9cbe --- /dev/null +++ b/salor-hospitality/spec/rails_helper.rb @@ -0,0 +1,59 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) +# Prevent database truncation if the environment is production +abort("The Rails environment is running in production mode!") if Rails.env.production? +require 'spec_helper' +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } + +# Checks for pending migration and applies them before tests are run. +# If you are not using ActiveRecord, you can remove this line. +ActiveRecord::Migration.maintain_test_schema! + +RSpec.configure do |config| + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, :type => :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") + config.include ActiveSupport::Testing::TimeHelpers + +end diff --git a/salor-hospitality/spec/spec_helper.rb b/salor-hospitality/spec/spec_helper.rb new file mode 100644 index 00000000..61e27385 --- /dev/null +++ b/salor-hospitality/spec/spec_helper.rb @@ -0,0 +1,92 @@ +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # These two settings work together to allow you to limit a spec run + # to individual examples or groups you care about by tagging them with + # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # get run. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = 'doc' + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end