deal_redemptions 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +30 -0
- data/app/assets/fonts/proximanova-light.eot +0 -0
- data/app/assets/fonts/proximanova-light.svg +542 -0
- data/app/assets/fonts/proximanova-light.ttf +0 -0
- data/app/assets/fonts/proximanova-light.woff +0 -0
- data/app/assets/fonts/proximanova-regular.eot +0 -0
- data/app/assets/fonts/proximanova-regular.svg +544 -0
- data/app/assets/fonts/proximanova-regular.ttf +0 -0
- data/app/assets/fonts/proximanova-regular.woff +0 -0
- data/app/assets/fonts/ss-glyphs.eot +0 -0
- data/app/assets/fonts/ss-glyphs.svg +17 -0
- data/app/assets/fonts/ss-glyphs.ttf +0 -0
- data/app/assets/fonts/ss-glyphs.woff +0 -0
- data/app/assets/images/admin/csv-demo.jpg +0 -0
- data/app/assets/images/deal-redemptions-logo.png +0 -0
- data/app/assets/javascripts/deal_redemptions/admin.js.coffee +77 -0
- data/app/assets/javascripts/deal_redemptions/application.js +17 -0
- data/app/assets/javascripts/deal_redemptions/redeem/redeem.js.coffee +49 -0
- data/app/assets/javascripts/deal_redemptions/redeem/redemption.js.coffee +41 -0
- data/app/assets/javascripts/deal_redemptions/redeem/validator.js.coffee +36 -0
- data/app/assets/javascripts/deal_redemptions/welcome.js.coffee +3 -0
- data/app/assets/stylesheets/deal_redemptions/admin.css.scss +505 -0
- data/app/assets/stylesheets/deal_redemptions/application.css.scss +57 -0
- data/app/assets/stylesheets/deal_redemptions/lib.css.scss +29 -0
- data/app/assets/stylesheets/deal_redemptions/redeem.css.scss +56 -0
- data/app/assets/stylesheets/deal_redemptions/welcome.css.scss +33 -0
- data/app/controllers/deal_redemptions/admin/companies_controller.rb +66 -0
- data/app/controllers/deal_redemptions/admin/dashboard_controller.rb +12 -0
- data/app/controllers/deal_redemptions/admin/import_controller.rb +47 -0
- data/app/controllers/deal_redemptions/admin/products_controller.rb +60 -0
- data/app/controllers/deal_redemptions/admin/redemptions_controller.rb +50 -0
- data/app/controllers/deal_redemptions/admin/sessions_controller.rb +26 -0
- data/app/controllers/deal_redemptions/admin/settings_controller.rb +14 -0
- data/app/controllers/deal_redemptions/admin/user_controller.rb +53 -0
- data/app/controllers/deal_redemptions/application_controller.rb +16 -0
- data/app/controllers/deal_redemptions/redeem_controller.rb +87 -0
- data/app/controllers/deal_redemptions/welcome_controller.rb +9 -0
- data/app/helpers/deal_redemptions/admin_helper.rb +30 -0
- data/app/helpers/deal_redemptions/application_helper.rb +8 -0
- data/app/helpers/deal_redemptions/redeem_helper.rb +4 -0
- data/app/helpers/deal_redemptions/welcome_helper.rb +4 -0
- data/app/mailers/deal_redemptions/admin_user_mailer.rb +11 -0
- data/app/mailers/deal_redemptions/redemption_mailer.rb +11 -0
- data/app/models/deal_redemptions/company.rb +27 -0
- data/app/models/deal_redemptions/mailing_list.rb +8 -0
- data/app/models/deal_redemptions/product.rb +18 -0
- data/app/models/deal_redemptions/redeem_code.rb +30 -0
- data/app/models/deal_redemptions/redemption.rb +14 -0
- data/app/models/deal_redemptions/redemptions/redeem.rb +21 -0
- data/app/models/deal_redemptions/user.rb +40 -0
- data/app/views/deal_redemptions/admin/companies/_form.html.haml +25 -0
- data/app/views/deal_redemptions/admin/companies/edit.html.haml +19 -0
- data/app/views/deal_redemptions/admin/companies/index.html.haml +32 -0
- data/app/views/deal_redemptions/admin/companies/new.html.haml +11 -0
- data/app/views/deal_redemptions/admin/dashboard/index.html.haml +4 -0
- data/app/views/deal_redemptions/admin/import/export_redemptions.csv.erb +1 -0
- data/app/views/deal_redemptions/admin/import/new.html.haml +54 -0
- data/app/views/deal_redemptions/admin/products/_form.html.haml +16 -0
- data/app/views/deal_redemptions/admin/products/edit.html.haml +18 -0
- data/app/views/deal_redemptions/admin/products/index.html.haml +26 -0
- data/app/views/deal_redemptions/admin/products/new.html.haml +11 -0
- data/app/views/deal_redemptions/admin/redemptions/index.html.haml +54 -0
- data/app/views/deal_redemptions/admin/redemptions/new.html.erb +5 -0
- data/app/views/deal_redemptions/admin/redemptions/show.html.haml +64 -0
- data/app/views/deal_redemptions/admin/sessions/new.html.haml +23 -0
- data/app/views/deal_redemptions/admin/settings/_new_user_modal.html.haml +38 -0
- data/app/views/deal_redemptions/admin/settings/index.html.haml +48 -0
- data/app/views/deal_redemptions/admin/shared/_sidebar.html.haml +16 -0
- data/app/views/deal_redemptions/admin/shared/_topbar.html.haml +5 -0
- data/app/views/deal_redemptions/admin_user_mailer/new_confirmation.html.erb +8 -0
- data/app/views/deal_redemptions/redeem/new.html.haml +112 -0
- data/app/views/deal_redemptions/redeem/thankyou.html.haml +6 -0
- data/app/views/deal_redemptions/redeem/validate_code.jbuilder +1 -0
- data/app/views/deal_redemptions/redemption_mailer/confirmation.html.erb +3 -0
- data/app/views/deal_redemptions/shared_partials/_powered.html.haml +4 -0
- data/app/views/deal_redemptions/welcome/index.html.haml +15 -0
- data/app/views/kaminari/_first_page.html.haml +9 -0
- data/app/views/kaminari/_gap.html.haml +8 -0
- data/app/views/kaminari/_last_page.html.haml +9 -0
- data/app/views/kaminari/_next_page.html.haml +9 -0
- data/app/views/kaminari/_page.html.haml +10 -0
- data/app/views/kaminari/_paginator.html.haml +18 -0
- data/app/views/kaminari/_prev_page.html.haml +9 -0
- data/app/views/layouts/deal_redemptions/admin/auth.html.erb +17 -0
- data/app/views/layouts/deal_redemptions/admin/default.html.erb +50 -0
- data/app/views/layouts/deal_redemptions/application.html.erb +16 -0
- data/config/config_engine_rake_file.rb +13 -0
- data/config/locales/en.yml +37 -0
- data/config/routes.rb +38 -0
- data/db/migrate/20140709234323_create_deal_redemptions_companies.rb +12 -0
- data/db/migrate/20140711183800_add_active_to_deal_redemptions_companies.rb +5 -0
- data/db/migrate/20140711222957_create_deal_redemptions_mailing_lists.rb +11 -0
- data/db/migrate/20140714165815_create_deal_redemptions_products.rb +10 -0
- data/db/migrate/20140714184807_create_deal_redemptions_redemptions.rb +20 -0
- data/db/migrate/20140715041757_create_deal_redemptions_redeem_codes.rb +13 -0
- data/db/migrate/20140718200319_create_deal_redemptions_users.rb +14 -0
- data/db/migrate/20140802010843_add_company_and_remove_transaction_to_redemption.rb +5 -0
- data/lib/deal_redemptions.rb +5 -0
- data/lib/deal_redemptions/admin/importer.rb +66 -0
- data/lib/deal_redemptions/admin_interface_domain.rb +11 -0
- data/lib/deal_redemptions/engine.rb +52 -0
- data/lib/deal_redemptions/version.rb +3 -0
- data/lib/tasks/deal_redemptions_tasks.rake +11 -0
- data/spec/controllers/deal_redemptions/admin/companies_controller_spec.rb +120 -0
- data/spec/controllers/deal_redemptions/admin/dashboard_controller_spec.rb +17 -0
- data/spec/controllers/deal_redemptions/admin/import_controller_spec.rb +32 -0
- data/spec/controllers/deal_redemptions/admin/products_controller_spec.rb +136 -0
- data/spec/controllers/deal_redemptions/admin/redemptions_controller_spec.rb +81 -0
- data/spec/controllers/deal_redemptions/admin/sessions_controller_spec.rb +15 -0
- data/spec/controllers/deal_redemptions/admin/settings_controller_spec.rb +28 -0
- data/spec/controllers/deal_redemptions/admin/user_controller_spec.rb +62 -0
- data/spec/controllers/deal_redemptions/redeem_controller_spec.rb +32 -0
- data/spec/controllers/deal_redemptions/welcome_controller_spec.rb +28 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +29 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +82 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/deal_redemptions.rb +13 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +85 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +1464 -0
- data/spec/dummy/log/test.log +242034 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/65dfde5f086fa3aca4c12e3ec1bab0e7 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d625417a15a40e26da10d62fd34927e1 +0 -0
- data/spec/factories/company.rb +21 -0
- data/spec/factories/deal_redemption_products.rb +9 -0
- data/spec/factories/deal_redemptions_redeem_codes.rb +11 -0
- data/spec/factories/deal_redemptions_redemptions.rb +51 -0
- data/spec/factories/deal_redemptions_users.rb +19 -0
- data/spec/factories/mailing_lists.rb +9 -0
- data/spec/mailers/deal_redemptions/admin_user_mailer_spec.rb +24 -0
- data/spec/mailers/deal_redemptions/redemption_mailer_spec.rb +24 -0
- data/spec/models/deal_redemptions/company_spec.rb +27 -0
- data/spec/models/deal_redemptions/mailing_list_spec.rb +14 -0
- data/spec/models/deal_redemptions/product_spec.rb +23 -0
- data/spec/models/deal_redemptions/redeem_code_spec.rb +57 -0
- data/spec/models/deal_redemptions/redemption_spec.rb +23 -0
- data/spec/models/deal_redemptions/redemptions/redeem_spec.rb +21 -0
- data/spec/models/deal_redemptions/user_spec.rb +39 -0
- data/spec/rails_helper.rb +43 -0
- data/spec/routing/deal_redemptions/admin/import_routing_spec.rb +21 -0
- data/spec/routing/deal_redemptions/admin/redemptions_routing_spec.rb +18 -0
- data/spec/routing/deal_redemptions/admin/user_controller_routing_spec.rb +11 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/tasks/tasks_spec.rb +20 -0
- data/spec/views/deal_redemptions/admin/dashboard/index.html.erb_spec.rb +5 -0
- data/spec/views/deal_redemptions/admin/import/index.html.erb_spec.rb +5 -0
- data/spec/views/deal_redemptions/admin/sessions/index.html.erb_spec.rb +5 -0
- data/spec/views/deal_redemptions/admin/settings/index.html.erb_spec.rb +5 -0
- data/vendor/assets/javascripts/bootstrap-datepicker.js +474 -0
- data/vendor/assets/stylesheets/datepicker.css +182 -0
- metadata +485 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module DealRedemptions
|
4
|
+
RSpec.describe RedeemCode, :type => :model do
|
5
|
+
|
6
|
+
context 'validations' do
|
7
|
+
it { should belong_to(:company) }
|
8
|
+
it { should belong_to(:product) }
|
9
|
+
it { should belong_to(:redemption) }
|
10
|
+
|
11
|
+
it { should validate_presence_of(:code) }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'enum status' do
|
15
|
+
before(:each) do
|
16
|
+
@redeem_code = FactoryGirl.build(:redeem_code)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns void status' do
|
20
|
+
@redeem_code.status = 0
|
21
|
+
|
22
|
+
expect(@redeem_code.void?).to eq(true)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns active status' do
|
26
|
+
@redeem_code.status = 1
|
27
|
+
|
28
|
+
expect(@redeem_code.active?).to eq(true)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns redeemed status' do
|
32
|
+
@redeem_code.status = 2
|
33
|
+
|
34
|
+
expect(@redeem_code.redeemed?).to eq(true)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'validate redemption code' do
|
39
|
+
before(:each) do
|
40
|
+
@company = FactoryGirl.create(:company)
|
41
|
+
@code = FactoryGirl.create(:redeem_code)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'return true if code is valid' do
|
45
|
+
expect(@code.validate_code({ company: @code.company.slug, code: @code.code })).to eq(true)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'return false if code is used or does not match' do
|
49
|
+
expect(@code.validate_code({ company: @code.company, code: '' })).to eq(false)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'return false params are not provided' do
|
53
|
+
expect(@code.validate_code({})).to eq(false)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module DealRedemptions
|
4
|
+
RSpec.describe Redemption, :type => :model do
|
5
|
+
before(:each) do
|
6
|
+
@redemption = FactoryGirl.build(:redemption)
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'validations' do
|
10
|
+
it { should validate_presence_of(:first_name) }
|
11
|
+
it { should validate_presence_of(:last_name) }
|
12
|
+
it { should validate_presence_of(:email_address) }
|
13
|
+
it { should validate_presence_of(:address1) }
|
14
|
+
it { should validate_presence_of(:state) }
|
15
|
+
it { should validate_presence_of(:zip_code) }
|
16
|
+
it { should validate_presence_of(:country) }
|
17
|
+
|
18
|
+
it 'passed with all required attributes' do
|
19
|
+
expect(@redemption).to be_valid
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module DealRedemptions
|
4
|
+
RSpec.describe DealRedemptions::Redemptions::Redeem do
|
5
|
+
let(:redeem) { DealRedemptions::Redemptions::Redeem.new(FactoryGirl.create(:company)) }
|
6
|
+
|
7
|
+
context 'validates redemption codes' do
|
8
|
+
subject { redeem }
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
@redeem_code = FactoryGirl.create :redeem_code
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has all valid codes' do
|
15
|
+
allow(subject).to receive(:validate_redeem_codes).with([@redeem_code]) { 0 }
|
16
|
+
|
17
|
+
expect(subject.validate_redeem_codes([@redeem_code])).to eq(0)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module DealRedemptions
|
4
|
+
RSpec.describe User, :type => :model do
|
5
|
+
let(:user) { FactoryGirl.build(:user) }
|
6
|
+
|
7
|
+
context 'validations' do
|
8
|
+
it { should validate_presence_of(:first_name) }
|
9
|
+
it { should validate_presence_of(:last_name) }
|
10
|
+
it { should validate_presence_of(:email) }
|
11
|
+
it { should validate_presence_of(:password) }
|
12
|
+
|
13
|
+
it { should validate_uniqueness_of(:email) }
|
14
|
+
|
15
|
+
it 'will not save user with a non-valid email format' do
|
16
|
+
user = FactoryGirl.build(:user, email: '')
|
17
|
+
|
18
|
+
expect(user.save).to eq(false)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'valid password encryption using bcrypt' do
|
23
|
+
it 'password hash populated' do
|
24
|
+
user.save
|
25
|
+
expect(user.password_hash).to_not be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'generated and stored password salt' do
|
29
|
+
user.save
|
30
|
+
expect(user.password_salt).to_not be_nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'log_last_login assigns current time before saving' do
|
35
|
+
user.save
|
36
|
+
expect(user.last_login).to_not be_nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
require 'spec_helper'
|
4
|
+
require File.expand_path("../../spec/dummy/config/environment", __FILE__)
|
5
|
+
require 'rspec/rails'
|
6
|
+
|
7
|
+
# Requires supporting ruby files with custom matchers and macros, etc, in
|
8
|
+
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
9
|
+
# run as spec files by default. This means that files in spec/support that end
|
10
|
+
# in _spec.rb will both be required and run as specs, causing the specs to be
|
11
|
+
# run twice. It is recommended that you do not name files matching this glob to
|
12
|
+
# end with _spec.rb. You can configure this pattern with with the --pattern
|
13
|
+
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
14
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
15
|
+
|
16
|
+
# Checks for pending migrations before tests are run.
|
17
|
+
# If you are not using ActiveRecord, you can remove this line.
|
18
|
+
ActiveRecord::Migration.maintain_test_schema!
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
22
|
+
#config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
23
|
+
|
24
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
25
|
+
# examples within a transaction, remove the following line or assign false
|
26
|
+
# instead of true.
|
27
|
+
config.use_transactional_fixtures = false
|
28
|
+
|
29
|
+
# RSpec Rails can automatically mix in different behaviours to your tests
|
30
|
+
# based on their file location, for example enabling you to call `get` and
|
31
|
+
# `post` in specs under `spec/controllers`.
|
32
|
+
#
|
33
|
+
# You can disable this behaviour by removing the line below, and instead
|
34
|
+
# explicitly tag your specs with their type, e.g.:
|
35
|
+
#
|
36
|
+
# RSpec.describe UsersController, :type => :controller do
|
37
|
+
# # ...
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# The different available types are documented in the features, such as in
|
41
|
+
# https://relishapp.com/rspec/rspec-rails/docs
|
42
|
+
config.infer_spec_type_from_file_location!
|
43
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module DealRedemptions
|
4
|
+
describe Admin::ImportController, type: :routing do
|
5
|
+
routes { DealRedemptions::Engine::routes }
|
6
|
+
|
7
|
+
describe 'routing' do
|
8
|
+
it 'get #index' do
|
9
|
+
expect(get: '/admin/transfer').to route_to('deal_redemptions/admin/import#new')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'post #create' do
|
13
|
+
expect(post: 'admin/transfer').to route_to('deal_redemptions/admin/import#create')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'get #export_redemptions' do
|
17
|
+
expect(get: '/admin/transfer/export_redemptions.csv').to route_to('deal_redemptions/admin/import#export_redemptions', format: 'csv')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
module DealRedemptions
|
4
|
+
RSpec.describe Admin::RedemptionsController, :type => :routing do
|
5
|
+
routes { DealRedemptions::Engine::routes }
|
6
|
+
describe "routing" do
|
7
|
+
describe "admin/redemptions" do
|
8
|
+
it "routes to #index" do
|
9
|
+
expect(:get => "/admin/redemptions").to route_to("deal_redemptions/admin/redemptions#index")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "routes to #show" do
|
13
|
+
expect(:get => "/admin/redemptions/1").to route_to("deal_redemptions/admin/redemptions#show", :id => "1")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
|
3
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
4
|
+
require 'rspec/rails'
|
5
|
+
#require 'rspec/autorun'
|
6
|
+
require 'factory_girl_rails'
|
7
|
+
require 'database_cleaner'
|
8
|
+
require 'shoulda/matchers'
|
9
|
+
|
10
|
+
Rails.backtrace_cleaner.remove_silencers!
|
11
|
+
|
12
|
+
# Load support files
|
13
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.mock_with :rspec
|
17
|
+
config.use_transactional_fixtures = true
|
18
|
+
config.infer_base_class_for_anonymous_controllers = false
|
19
|
+
config.order = "random"
|
20
|
+
|
21
|
+
config.before(:suite) do
|
22
|
+
DatabaseCleaner.strategy = :transaction
|
23
|
+
DatabaseCleaner.clean_with(:truncation)
|
24
|
+
end
|
25
|
+
config.before(:each) do
|
26
|
+
DatabaseCleaner.start
|
27
|
+
end
|
28
|
+
config.after(:each) do
|
29
|
+
DatabaseCleaner.clean
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
describe 'deal redemption tasks' do
|
5
|
+
before :each do
|
6
|
+
@rake = Rake::Application.new
|
7
|
+
Rake.application = @rake
|
8
|
+
DealRedemptions::Engine.load_tasks
|
9
|
+
Rake::Task.define_task(:environment)
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'deal_redemptions:install:config' do
|
13
|
+
subject { @rake['deal_redemptions:install:config'] }
|
14
|
+
|
15
|
+
it 'generates config file in destination' do
|
16
|
+
subject.invoke
|
17
|
+
expect(File.exists?("#{Rails.root}/config/initializers/deal_redemptions.rb")).to eq(true)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,474 @@
|
|
1
|
+
/* =========================================================
|
2
|
+
* bootstrap-datepicker.js
|
3
|
+
* http://www.eyecon.ro/bootstrap-datepicker
|
4
|
+
* =========================================================
|
5
|
+
* Copyright 2012 Stefan Petre
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
* ========================================================= */
|
19
|
+
|
20
|
+
!function( $ ) {
|
21
|
+
|
22
|
+
// Picker object
|
23
|
+
|
24
|
+
var Datepicker = function(element, options){
|
25
|
+
this.element = $(element);
|
26
|
+
this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||'mm/dd/yyyy');
|
27
|
+
this.picker = $(DPGlobal.template)
|
28
|
+
.appendTo('body')
|
29
|
+
.on({
|
30
|
+
click: $.proxy(this.click, this)//,
|
31
|
+
//mousedown: $.proxy(this.mousedown, this)
|
32
|
+
});
|
33
|
+
this.isInput = this.element.is('input');
|
34
|
+
this.component = this.element.is('.date') ? this.element.find('.add-on') : false;
|
35
|
+
|
36
|
+
if (this.isInput) {
|
37
|
+
this.element.on({
|
38
|
+
focus: $.proxy(this.show, this),
|
39
|
+
//blur: $.proxy(this.hide, this),
|
40
|
+
keyup: $.proxy(this.update, this)
|
41
|
+
});
|
42
|
+
} else {
|
43
|
+
if (this.component){
|
44
|
+
this.component.on('click', $.proxy(this.show, this));
|
45
|
+
} else {
|
46
|
+
this.element.on('click', $.proxy(this.show, this));
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
this.minViewMode = options.minViewMode||this.element.data('date-minviewmode')||0;
|
51
|
+
if (typeof this.minViewMode === 'string') {
|
52
|
+
switch (this.minViewMode) {
|
53
|
+
case 'months':
|
54
|
+
this.minViewMode = 1;
|
55
|
+
break;
|
56
|
+
case 'years':
|
57
|
+
this.minViewMode = 2;
|
58
|
+
break;
|
59
|
+
default:
|
60
|
+
this.minViewMode = 0;
|
61
|
+
break;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
this.viewMode = options.viewMode||this.element.data('date-viewmode')||0;
|
65
|
+
if (typeof this.viewMode === 'string') {
|
66
|
+
switch (this.viewMode) {
|
67
|
+
case 'months':
|
68
|
+
this.viewMode = 1;
|
69
|
+
break;
|
70
|
+
case 'years':
|
71
|
+
this.viewMode = 2;
|
72
|
+
break;
|
73
|
+
default:
|
74
|
+
this.viewMode = 0;
|
75
|
+
break;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
this.startViewMode = this.viewMode;
|
79
|
+
this.weekStart = options.weekStart||this.element.data('date-weekstart')||0;
|
80
|
+
this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
|
81
|
+
this.onRender = options.onRender;
|
82
|
+
this.fillDow();
|
83
|
+
this.fillMonths();
|
84
|
+
this.update();
|
85
|
+
this.showMode();
|
86
|
+
};
|
87
|
+
|
88
|
+
Datepicker.prototype = {
|
89
|
+
constructor: Datepicker,
|
90
|
+
|
91
|
+
show: function(e) {
|
92
|
+
this.picker.show();
|
93
|
+
this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
|
94
|
+
this.place();
|
95
|
+
$(window).on('resize', $.proxy(this.place, this));
|
96
|
+
if (e ) {
|
97
|
+
e.stopPropagation();
|
98
|
+
e.preventDefault();
|
99
|
+
}
|
100
|
+
if (!this.isInput) {
|
101
|
+
}
|
102
|
+
var that = this;
|
103
|
+
$(document).on('mousedown', function(ev){
|
104
|
+
if ($(ev.target).closest('.datepicker').length == 0) {
|
105
|
+
that.hide();
|
106
|
+
}
|
107
|
+
});
|
108
|
+
this.element.trigger({
|
109
|
+
type: 'show',
|
110
|
+
date: this.date
|
111
|
+
});
|
112
|
+
},
|
113
|
+
|
114
|
+
hide: function(){
|
115
|
+
this.picker.hide();
|
116
|
+
$(window).off('resize', this.place);
|
117
|
+
this.viewMode = this.startViewMode;
|
118
|
+
this.showMode();
|
119
|
+
if (!this.isInput) {
|
120
|
+
$(document).off('mousedown', this.hide);
|
121
|
+
}
|
122
|
+
//this.set();
|
123
|
+
this.element.trigger({
|
124
|
+
type: 'hide',
|
125
|
+
date: this.date
|
126
|
+
});
|
127
|
+
},
|
128
|
+
|
129
|
+
set: function() {
|
130
|
+
var formated = DPGlobal.formatDate(this.date, this.format);
|
131
|
+
if (!this.isInput) {
|
132
|
+
if (this.component){
|
133
|
+
this.element.find('input').prop('value', formated);
|
134
|
+
}
|
135
|
+
this.element.data('date', formated);
|
136
|
+
} else {
|
137
|
+
this.element.prop('value', formated);
|
138
|
+
}
|
139
|
+
},
|
140
|
+
|
141
|
+
setValue: function(newDate) {
|
142
|
+
if (typeof newDate === 'string') {
|
143
|
+
this.date = DPGlobal.parseDate(newDate, this.format);
|
144
|
+
} else {
|
145
|
+
this.date = new Date(newDate);
|
146
|
+
}
|
147
|
+
this.set();
|
148
|
+
this.viewDate = new Date(this.date.getFullYear(), this.date.getMonth(), 1, 0, 0, 0, 0);
|
149
|
+
this.fill();
|
150
|
+
},
|
151
|
+
|
152
|
+
place: function(){
|
153
|
+
var offset = this.component ? this.component.offset() : this.element.offset();
|
154
|
+
this.picker.css({
|
155
|
+
top: offset.top + this.height,
|
156
|
+
left: offset.left
|
157
|
+
});
|
158
|
+
},
|
159
|
+
|
160
|
+
update: function(newDate){
|
161
|
+
this.date = DPGlobal.parseDate(
|
162
|
+
typeof newDate === 'string' ? newDate : (this.isInput ? this.element.prop('value') : this.element.data('date')),
|
163
|
+
this.format
|
164
|
+
);
|
165
|
+
this.viewDate = new Date(this.date.getFullYear(), this.date.getMonth(), 1, 0, 0, 0, 0);
|
166
|
+
this.fill();
|
167
|
+
},
|
168
|
+
|
169
|
+
fillDow: function(){
|
170
|
+
var dowCnt = this.weekStart;
|
171
|
+
var html = '<tr>';
|
172
|
+
while (dowCnt < this.weekStart + 7) {
|
173
|
+
html += '<th class="dow">'+DPGlobal.dates.daysMin[(dowCnt++)%7]+'</th>';
|
174
|
+
}
|
175
|
+
html += '</tr>';
|
176
|
+
this.picker.find('.datepicker-days thead').append(html);
|
177
|
+
},
|
178
|
+
|
179
|
+
fillMonths: function(){
|
180
|
+
var html = '';
|
181
|
+
var i = 0
|
182
|
+
while (i < 12) {
|
183
|
+
html += '<span class="month">'+DPGlobal.dates.monthsShort[i++]+'</span>';
|
184
|
+
}
|
185
|
+
this.picker.find('.datepicker-months td').append(html);
|
186
|
+
},
|
187
|
+
|
188
|
+
fill: function() {
|
189
|
+
var d = new Date(this.viewDate),
|
190
|
+
year = d.getFullYear(),
|
191
|
+
month = d.getMonth(),
|
192
|
+
currentDate = this.date.valueOf();
|
193
|
+
this.picker.find('.datepicker-days th:eq(1)')
|
194
|
+
.text(DPGlobal.dates.months[month]+' '+year);
|
195
|
+
var prevMonth = new Date(year, month-1, 28,0,0,0,0),
|
196
|
+
day = DPGlobal.getDaysInMonth(prevMonth.getFullYear(), prevMonth.getMonth());
|
197
|
+
prevMonth.setDate(day);
|
198
|
+
prevMonth.setDate(day - (prevMonth.getDay() - this.weekStart + 7)%7);
|
199
|
+
var nextMonth = new Date(prevMonth);
|
200
|
+
nextMonth.setDate(nextMonth.getDate() + 42);
|
201
|
+
nextMonth = nextMonth.valueOf();
|
202
|
+
var html = [];
|
203
|
+
var clsName,
|
204
|
+
prevY,
|
205
|
+
prevM;
|
206
|
+
while(prevMonth.valueOf() < nextMonth) {
|
207
|
+
if (prevMonth.getDay() === this.weekStart) {
|
208
|
+
html.push('<tr>');
|
209
|
+
}
|
210
|
+
clsName = this.onRender(prevMonth);
|
211
|
+
prevY = prevMonth.getFullYear();
|
212
|
+
prevM = prevMonth.getMonth();
|
213
|
+
if ((prevM < month && prevY === year) || prevY < year) {
|
214
|
+
clsName += ' old';
|
215
|
+
} else if ((prevM > month && prevY === year) || prevY > year) {
|
216
|
+
clsName += ' new';
|
217
|
+
}
|
218
|
+
if (prevMonth.valueOf() === currentDate) {
|
219
|
+
clsName += ' active';
|
220
|
+
}
|
221
|
+
html.push('<td class="day '+clsName+'">'+prevMonth.getDate() + '</td>');
|
222
|
+
if (prevMonth.getDay() === this.weekEnd) {
|
223
|
+
html.push('</tr>');
|
224
|
+
}
|
225
|
+
prevMonth.setDate(prevMonth.getDate()+1);
|
226
|
+
}
|
227
|
+
this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
|
228
|
+
var currentYear = this.date.getFullYear();
|
229
|
+
|
230
|
+
var months = this.picker.find('.datepicker-months')
|
231
|
+
.find('th:eq(1)')
|
232
|
+
.text(year)
|
233
|
+
.end()
|
234
|
+
.find('span').removeClass('active');
|
235
|
+
if (currentYear === year) {
|
236
|
+
months.eq(this.date.getMonth()).addClass('active');
|
237
|
+
}
|
238
|
+
|
239
|
+
html = '';
|
240
|
+
year = parseInt(year/10, 10) * 10;
|
241
|
+
var yearCont = this.picker.find('.datepicker-years')
|
242
|
+
.find('th:eq(1)')
|
243
|
+
.text(year + '-' + (year + 9))
|
244
|
+
.end()
|
245
|
+
.find('td');
|
246
|
+
year -= 1;
|
247
|
+
for (var i = -1; i < 11; i++) {
|
248
|
+
html += '<span class="year'+(i === -1 || i === 10 ? ' old' : '')+(currentYear === year ? ' active' : '')+'">'+year+'</span>';
|
249
|
+
year += 1;
|
250
|
+
}
|
251
|
+
yearCont.html(html);
|
252
|
+
},
|
253
|
+
|
254
|
+
click: function(e) {
|
255
|
+
e.stopPropagation();
|
256
|
+
e.preventDefault();
|
257
|
+
var target = $(e.target).closest('span, td, th');
|
258
|
+
if (target.length === 1) {
|
259
|
+
switch(target[0].nodeName.toLowerCase()) {
|
260
|
+
case 'th':
|
261
|
+
switch(target[0].className) {
|
262
|
+
case 'switch':
|
263
|
+
this.showMode(1);
|
264
|
+
break;
|
265
|
+
case 'prev':
|
266
|
+
case 'next':
|
267
|
+
this.viewDate['set'+DPGlobal.modes[this.viewMode].navFnc].call(
|
268
|
+
this.viewDate,
|
269
|
+
this.viewDate['get'+DPGlobal.modes[this.viewMode].navFnc].call(this.viewDate) +
|
270
|
+
DPGlobal.modes[this.viewMode].navStep * (target[0].className === 'prev' ? -1 : 1)
|
271
|
+
);
|
272
|
+
this.fill();
|
273
|
+
this.set();
|
274
|
+
break;
|
275
|
+
}
|
276
|
+
break;
|
277
|
+
case 'span':
|
278
|
+
if (target.is('.month')) {
|
279
|
+
var month = target.parent().find('span').index(target);
|
280
|
+
this.viewDate.setMonth(month);
|
281
|
+
} else {
|
282
|
+
var year = parseInt(target.text(), 10)||0;
|
283
|
+
this.viewDate.setFullYear(year);
|
284
|
+
}
|
285
|
+
if (this.viewMode !== 0) {
|
286
|
+
this.date = new Date(this.viewDate);
|
287
|
+
this.element.trigger({
|
288
|
+
type: 'changeDate',
|
289
|
+
date: this.date,
|
290
|
+
viewMode: DPGlobal.modes[this.viewMode].clsName
|
291
|
+
});
|
292
|
+
}
|
293
|
+
this.showMode(-1);
|
294
|
+
this.fill();
|
295
|
+
this.set();
|
296
|
+
break;
|
297
|
+
case 'td':
|
298
|
+
if (target.is('.day') && !target.is('.disabled')){
|
299
|
+
var day = parseInt(target.text(), 10)||1;
|
300
|
+
var month = this.viewDate.getMonth();
|
301
|
+
if (target.is('.old')) {
|
302
|
+
month -= 1;
|
303
|
+
} else if (target.is('.new')) {
|
304
|
+
month += 1;
|
305
|
+
}
|
306
|
+
var year = this.viewDate.getFullYear();
|
307
|
+
this.date = new Date(year, month, day,0,0,0,0);
|
308
|
+
this.viewDate = new Date(year, month, Math.min(28, day),0,0,0,0);
|
309
|
+
this.fill();
|
310
|
+
this.set();
|
311
|
+
this.element.trigger({
|
312
|
+
type: 'changeDate',
|
313
|
+
date: this.date,
|
314
|
+
viewMode: DPGlobal.modes[this.viewMode].clsName
|
315
|
+
});
|
316
|
+
}
|
317
|
+
break;
|
318
|
+
}
|
319
|
+
}
|
320
|
+
},
|
321
|
+
|
322
|
+
mousedown: function(e){
|
323
|
+
e.stopPropagation();
|
324
|
+
e.preventDefault();
|
325
|
+
},
|
326
|
+
|
327
|
+
showMode: function(dir) {
|
328
|
+
if (dir) {
|
329
|
+
this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
|
330
|
+
}
|
331
|
+
this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
|
332
|
+
}
|
333
|
+
};
|
334
|
+
|
335
|
+
$.fn.datepicker = function ( option, val ) {
|
336
|
+
return this.each(function () {
|
337
|
+
var $this = $(this),
|
338
|
+
data = $this.data('datepicker'),
|
339
|
+
options = typeof option === 'object' && option;
|
340
|
+
if (!data) {
|
341
|
+
$this.data('datepicker', (data = new Datepicker(this, $.extend({}, $.fn.datepicker.defaults,options))));
|
342
|
+
}
|
343
|
+
if (typeof option === 'string') data[option](val);
|
344
|
+
});
|
345
|
+
};
|
346
|
+
|
347
|
+
$.fn.datepicker.defaults = {
|
348
|
+
onRender: function(date) {
|
349
|
+
return '';
|
350
|
+
}
|
351
|
+
};
|
352
|
+
$.fn.datepicker.Constructor = Datepicker;
|
353
|
+
|
354
|
+
var DPGlobal = {
|
355
|
+
modes: [
|
356
|
+
{
|
357
|
+
clsName: 'days',
|
358
|
+
navFnc: 'Month',
|
359
|
+
navStep: 1
|
360
|
+
},
|
361
|
+
{
|
362
|
+
clsName: 'months',
|
363
|
+
navFnc: 'FullYear',
|
364
|
+
navStep: 1
|
365
|
+
},
|
366
|
+
{
|
367
|
+
clsName: 'years',
|
368
|
+
navFnc: 'FullYear',
|
369
|
+
navStep: 10
|
370
|
+
}],
|
371
|
+
dates:{
|
372
|
+
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
|
373
|
+
daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
|
374
|
+
daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
|
375
|
+
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
376
|
+
monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
377
|
+
},
|
378
|
+
isLeapYear: function (year) {
|
379
|
+
return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0))
|
380
|
+
},
|
381
|
+
getDaysInMonth: function (year, month) {
|
382
|
+
return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]
|
383
|
+
},
|
384
|
+
parseFormat: function(format){
|
385
|
+
var separator = format.match(/[.\/\-\s].*?/),
|
386
|
+
parts = format.split(/\W+/);
|
387
|
+
if (!separator || !parts || parts.length === 0){
|
388
|
+
throw new Error("Invalid date format.");
|
389
|
+
}
|
390
|
+
return {separator: separator, parts: parts};
|
391
|
+
},
|
392
|
+
parseDate: function(date, format) {
|
393
|
+
var parts = date.split(format.separator),
|
394
|
+
date = new Date(),
|
395
|
+
val;
|
396
|
+
date.setHours(0);
|
397
|
+
date.setMinutes(0);
|
398
|
+
date.setSeconds(0);
|
399
|
+
date.setMilliseconds(0);
|
400
|
+
if (parts.length === format.parts.length) {
|
401
|
+
var year = date.getFullYear(), day = date.getDate(), month = date.getMonth();
|
402
|
+
for (var i=0, cnt = format.parts.length; i < cnt; i++) {
|
403
|
+
val = parseInt(parts[i], 10)||1;
|
404
|
+
switch(format.parts[i]) {
|
405
|
+
case 'dd':
|
406
|
+
case 'd':
|
407
|
+
day = val;
|
408
|
+
date.setDate(val);
|
409
|
+
break;
|
410
|
+
case 'mm':
|
411
|
+
case 'm':
|
412
|
+
month = val - 1;
|
413
|
+
date.setMonth(val - 1);
|
414
|
+
break;
|
415
|
+
case 'yy':
|
416
|
+
year = 2000 + val;
|
417
|
+
date.setFullYear(2000 + val);
|
418
|
+
break;
|
419
|
+
case 'yyyy':
|
420
|
+
year = val;
|
421
|
+
date.setFullYear(val);
|
422
|
+
break;
|
423
|
+
}
|
424
|
+
}
|
425
|
+
date = new Date(year, month, day, 0 ,0 ,0);
|
426
|
+
}
|
427
|
+
return date;
|
428
|
+
},
|
429
|
+
formatDate: function(date, format){
|
430
|
+
var val = {
|
431
|
+
d: date.getDate(),
|
432
|
+
m: date.getMonth() + 1,
|
433
|
+
yy: date.getFullYear().toString().substring(2),
|
434
|
+
yyyy: date.getFullYear()
|
435
|
+
};
|
436
|
+
val.dd = (val.d < 10 ? '0' : '') + val.d;
|
437
|
+
val.mm = (val.m < 10 ? '0' : '') + val.m;
|
438
|
+
var date = [];
|
439
|
+
for (var i=0, cnt = format.parts.length; i < cnt; i++) {
|
440
|
+
date.push(val[format.parts[i]]);
|
441
|
+
}
|
442
|
+
return date.join(format.separator);
|
443
|
+
},
|
444
|
+
headTemplate: '<thead>'+
|
445
|
+
'<tr>'+
|
446
|
+
'<th class="prev">‹</th>'+
|
447
|
+
'<th colspan="5" class="switch"></th>'+
|
448
|
+
'<th class="next">›</th>'+
|
449
|
+
'</tr>'+
|
450
|
+
'</thead>',
|
451
|
+
contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>'
|
452
|
+
};
|
453
|
+
DPGlobal.template = '<div class="datepicker dropdown-menu">'+
|
454
|
+
'<div class="datepicker-days">'+
|
455
|
+
'<table class=" table-condensed">'+
|
456
|
+
DPGlobal.headTemplate+
|
457
|
+
'<tbody></tbody>'+
|
458
|
+
'</table>'+
|
459
|
+
'</div>'+
|
460
|
+
'<div class="datepicker-months">'+
|
461
|
+
'<table class="table-condensed">'+
|
462
|
+
DPGlobal.headTemplate+
|
463
|
+
DPGlobal.contTemplate+
|
464
|
+
'</table>'+
|
465
|
+
'</div>'+
|
466
|
+
'<div class="datepicker-years">'+
|
467
|
+
'<table class="table-condensed">'+
|
468
|
+
DPGlobal.headTemplate+
|
469
|
+
DPGlobal.contTemplate+
|
470
|
+
'</table>'+
|
471
|
+
'</div>'+
|
472
|
+
'</div>';
|
473
|
+
|
474
|
+
}( window.jQuery );
|