Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specs and make seeds DB independent #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion salor-hospitality/.rspec
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--colour
--color
--require spec_helper
16 changes: 14 additions & 2 deletions salor-hospitality/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
117 changes: 86 additions & 31 deletions salor-hospitality/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
8 changes: 4 additions & 4 deletions salor-hospitality/app/models/season.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Season < ActiveRecord::Base
include Scope
include Base

belongs_to :vendor
belongs_to :company
has_many :surcharges
Expand All @@ -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
Expand Down
32 changes: 32 additions & 0 deletions salor-hospitality/spec/factories/season_factory.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions salor-hospitality/spec/models/receipt_spec.rb
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions salor-hospitality/spec/models/season_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading