diff --git a/Gemfile b/Gemfile index 65c8ac7c..f554c89a 100644 --- a/Gemfile +++ b/Gemfile @@ -46,6 +46,10 @@ end group :test do gem 'rspec-rails' + #gem 'minitest' + gem 'turn', :require => false + gem 'factory_girl_rails' + gem 'selenium-webdriver' #, '2.21.1' # 2.21.2 gives trouble, remove this line when this is solved since this is a dependency of capybara gem 'capybara' end diff --git a/Gemfile.lock b/Gemfile.lock index d3788551..ba7e4797 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -47,6 +47,7 @@ GEM i18n (~> 0.6) multi_json (~> 1.0) addressable (2.3.2) + ansi (1.4.3) arel (3.0.2) bcrypt-ruby (3.0.1) builder (3.0.0) @@ -85,6 +86,11 @@ GEM eventmachine (0.12.10) execjs (1.4.0) multi_json (~> 1.0) + factory_girl (4.0.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.0.0) + factory_girl (~> 4.0.0) + railties (>= 3.0.0) ffi (1.1.5) haml (3.1.7) haml-rails (0.3.4) @@ -203,6 +209,8 @@ GEM treetop (1.4.10) polyglot polyglot (>= 0.3.1) + turn (0.9.6) + ansi twitter-bootstrap-rails (2.1.3) actionpack (>= 3.1) less-rails (~> 2.2.3) @@ -226,6 +234,7 @@ DEPENDENCIES couch_potato! devise (= 2.0.4) devise_simply_stored + factory_girl_rails haml-rails jquery-rails mini_magick @@ -234,8 +243,10 @@ DEPENDENCIES rqrcode-rails3 rspec-rails sass-rails (~> 3.2.3) + selenium-webdriver simply_stored! slim-rails thin + turn twitter-bootstrap-rails uglifier (>= 1.0.3) diff --git a/app/assets/images/.DS_Store b/app/assets/images/.DS_Store new file mode 100644 index 00000000..1c767137 Binary files /dev/null and b/app/assets/images/.DS_Store differ diff --git a/app/assets/images/frames/.DS_Store b/app/assets/images/frames/.DS_Store new file mode 100644 index 00000000..987a5143 Binary files /dev/null and b/app/assets/images/frames/.DS_Store differ diff --git a/app/assets/images/frames/smartphone.png b/app/assets/images/frames/smartphone.png new file mode 100644 index 00000000..2da93844 Binary files /dev/null and b/app/assets/images/frames/smartphone.png differ diff --git a/app/assets/images/frames/smartphone.svg b/app/assets/images/frames/smartphone.svg new file mode 100644 index 00000000..3785ef65 --- /dev/null +++ b/app/assets/images/frames/smartphone.svg @@ -0,0 +1,685 @@ + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + V + + + odafone + + + + 11:45 + + + pm + + \ No newline at end of file diff --git a/app/assets/images/frames/tablet.png b/app/assets/images/frames/tablet.png new file mode 100644 index 00000000..489388ac Binary files /dev/null and b/app/assets/images/frames/tablet.png differ diff --git a/app/assets/images/frames/tablet.svg b/app/assets/images/frames/tablet.svg new file mode 100644 index 00000000..629e4f12 --- /dev/null +++ b/app/assets/images/frames/tablet.svg @@ -0,0 +1,894 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/assets/javascripts/qrammer.js.coffee b/app/assets/javascripts/qrammer.js.coffee index 52d6b836..c95afdc1 100644 --- a/app/assets/javascripts/qrammer.js.coffee +++ b/app/assets/javascripts/qrammer.js.coffee @@ -59,8 +59,8 @@ root.Qrammer = return window.location = '/' if res['message'] && !res['ok'] window.location = '/view_active_list' if res['ok'] - load_active_order_list: (supplier_id) -> - $.get('/suppliers/'+supplier_id+'/active_order_list.json', (res) -> + load_active_orders: (supplier_id) -> + $.get('/suppliers/'+supplier_id+'/active_orders.json', (res) -> body = $('#active-orders-table tbody') body.find('tr').remove() foot = $('#active-orders-table tfoot') @@ -112,7 +112,11 @@ root.Qrammer = )(list, row) close_btn.click(close_callback) - row.append($('').text(list._id)) + icons_td = $('').appendTo(row) + icons_td.append('
  • ') if list.need_help # or icon-bell + icons_td.append('
  • ') if list.needs_payment + + row.append($('').text(list.table_number)) row.append($('').html(Qrammer.currency(list.total_amount))) td_buttons = $('') td_buttons.append(close_btn) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 3192ec89..0f96e07c 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -9,5 +9,5 @@ * compiled file, but it's generally better to create a new file per style scope. * *= require_self - *= require_tree . + *= require_directory . */ diff --git a/app/assets/stylesheets/phone/application.css b/app/assets/stylesheets/phone/application.css new file mode 100644 index 00000000..0f96e07c --- /dev/null +++ b/app/assets/stylesheets/phone/application.css @@ -0,0 +1,13 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the top of the + * compiled file, but it's generally better to create a new file per style scope. + * + *= require_self + *= require_directory . + */ diff --git a/app/assets/stylesheets/phone/structure.css.sass b/app/assets/stylesheets/phone/structure.css.sass new file mode 100644 index 00000000..59ee6ae5 --- /dev/null +++ b/app/assets/stylesheets/phone/structure.css.sass @@ -0,0 +1,7 @@ +body + padding-left: 0px + padding-right: 0px + //padding-top: 50px + .navbar-fixed-top + margin-left: 0px + margin-right: 0px diff --git a/app/assets/stylesheets/structure.css.sass b/app/assets/stylesheets/structure.css.sass index f2020f5d..b3d14642 100644 --- a/app/assets/stylesheets/structure.css.sass +++ b/app/assets/stylesheets/structure.css.sass @@ -31,3 +31,33 @@ table td &:first-child background-image: image-url('icons/order-doublecheck.png') +.phone-wrapper + position: absolute + top: 60px + left: 20px + width: 353px + height: 693px + background-image: image-url('frames/smartphone.png') + background-repeat: no-repeat +.phone-content-frame + position: absolute + left: 40px + top: 182px + height: 482px + width: 310px + + +.tablet-wrapper + position: absolute + top: 60px + left: 393px + width: 1002px + height: 670px + background-image: image-url('frames/tablet.png') + background-repeat: no-repeat +.tablet-content-frame + position: absolute + left: 433px + top: 100px + width: 880px + height: 590px diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 5d734330..b128434f 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -4,10 +4,14 @@ class DashboardController < ApplicationController def home end + def phone_home + render layout: 'phone' + end # Testing action def select_qrcode @tables = Table.all + render layout: 'phone' end def create_list @@ -25,8 +29,7 @@ class DashboardController < ApplicationController def show_products @supplier = Supplier.first - - + render layout: 'phone' end def order_active_list @@ -50,6 +53,29 @@ class DashboardController < ApplicationController def view_active_list redirect_to(root_path, alert: t('messages.there_is_no_list_active')) and return unless session[:active_list_id].present? - + render layout: 'phone' + end + + ## + # Displays the closed lists of the user + def user_history + render layout: 'phone' + end + + def list_info + respond_to do |format| + format.json do + render json: {list_active: false} and return unless session[:active_list_id].present? + render json: active_list.as_json.merge(list_active: true) + end + end + end + + def supplier_home + redirect_to active_orders_supplier_path(Supplier.first) + end + + def supplier_lists + redirect_to active_lists_supplier_path(Supplier.first) end end diff --git a/app/controllers/suppliers_controller.rb b/app/controllers/suppliers_controller.rb index 943ff279..83b93934 100644 --- a/app/controllers/suppliers_controller.rb +++ b/app/controllers/suppliers_controller.rb @@ -99,12 +99,12 @@ class SuppliersController < ApplicationController end end - # GET /suppliers/1/active_order_list - # GET /suppliers/1/active_order_list.json - def active_order_list + # GET /suppliers/1/active_orders + # GET /suppliers/1/active_orders.json + def active_orders @supplier = Supplier.find(params[:id]) respond_to do |format| - format.html + format.html { render layout: 'tablet' } format.json do h = @supplier.as_json h[:orders] = [] @@ -124,7 +124,7 @@ class SuppliersController < ApplicationController h[:orders] << ho end h[:total_amount] = list_total.round(2) - render json: h + render json: h, layout: 'tablet' end end end @@ -134,7 +134,7 @@ class SuppliersController < ApplicationController def active_lists @supplier = Supplier.find(params[:id]) respond_to do |format| - format.html + format.html { render layout: 'tablet' } format.json do h = @supplier.as_json h[:lists] = [] @@ -146,7 +146,7 @@ class SuppliersController < ApplicationController h[:lists] << hl end h[:total_amount] = grand_total.round(2) - render json: h + render json: h, layout: 'tablet' end end end diff --git a/app/models/list.rb b/app/models/list.rb index 6b29e5f6..17e35f52 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -22,6 +22,10 @@ class List table.supplier end + def table_number + @table_number ||= table.number + end + def active? state == 'active' end @@ -35,4 +39,8 @@ class List ProductOrder.create order: @order, product_id: product_id, amount: number if number > 0 end end + + def as_json + super.merge(table_number: table_number) + end end diff --git a/app/views/dashboard/home.html.slim b/app/views/dashboard/home.html.slim index ae7f30df..ae518566 100644 --- a/app/views/dashboard/home.html.slim +++ b/app/views/dashboard/home.html.slim @@ -1,15 +1,5 @@ -.page-header= title 'Home' -ul.nav.nav-tabs.nav-stacked - - if list_open? - li= link_to 'Place order', '/show_products?supplier_id=' + active_list.supplier.id - li= link_to 'Active list', view_active_list_path - li= link_to 'Request bill', '#' - li= link_to 'I have a question', '#' - - else - li= link_to 'Place order', '/select_qrcode' - li= link_to 'Subscribe to list', '#' - li= link_to 'Check out menu', '#' - -ul.nav.nav-tabs.nav-stacked - li= link_to 'View history', '#' +.phone-wrapper +iframe.phone-content-frame src=phone_root_path +.tablet-wrapper +iframe.tablet-content-frame src=supplier_root_path diff --git a/app/views/dashboard/phone_home.html.slim b/app/views/dashboard/phone_home.html.slim new file mode 100644 index 00000000..55f3673d --- /dev/null +++ b/app/views/dashboard/phone_home.html.slim @@ -0,0 +1,11 @@ +ul.nav.nav-tabs.nav-stacked + - if list_open? + li= link_to 'Place order', '/show_products?supplier_id=' + active_list.supplier.id + li= link_to 'Active list', view_active_list_path + li= link_to 'Request bill', '#' + li= link_to 'Move table', '#' + li= link_to 'I have a question', '#' + - else + li= link_to 'Place order', '/select_qrcode' + li= link_to 'Subscribe to list', '#' + li= link_to 'Check out menu', '#' diff --git a/app/views/dashboard/show_products.html.slim b/app/views/dashboard/show_products.html.slim index 33eaa156..8c008dfa 100644 --- a/app/views/dashboard/show_products.html.slim +++ b/app/views/dashboard/show_products.html.slim @@ -1,24 +1,23 @@ -button onClick='Qrammer.build_product_list()' class='btn btn-inverse'Lijst table#products-table.table.table-striped.table-hover tbody -- content_for :sidebar do - table#active-order-table.table.hide - thead - tr - th Product - th # - th.currency Total - th - tbody - tfoot - tr - td colspan=2 - button class="btn btn-primary" onClick="Qrammer.order_active_list('/order_active_list')" Bestellen - |  - button class="btn btn btn-warning" onClick="Qrammer.clear_active_list()" Clear - td.currency - strong#active-order-total - td +-# content_for :sidebar do +table#active-order-table.table.table-striped.hide + thead + tr + th Product + th # + th.currency Total + th + tbody + tfoot + tr + td colspan=2 + button class="btn btn-primary" onClick="Qrammer.order_active_list('/order_active_list')" Bestellen + |  + button class="btn btn btn-warning" onClick="Qrammer.clear_active_list()" Clear + td.currency + strong#active-order-total + td - content_for :footer do javascript: jQuery(function(){ diff --git a/app/views/dashboard/user_history.html.slim b/app/views/dashboard/user_history.html.slim new file mode 100644 index 00000000..a89aef96 --- /dev/null +++ b/app/views/dashboard/user_history.html.slim @@ -0,0 +1,2 @@ +.page-header= title 'User history' +p Todo diff --git a/app/views/layouts/phone.html.slim b/app/views/layouts/phone.html.slim new file mode 100644 index 00000000..9e7e84ed --- /dev/null +++ b/app/views/layouts/phone.html.slim @@ -0,0 +1,55 @@ +doctype html +html lang="en" + head + meta charset="utf-8" + meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" + meta name="viewport" content="width=device-width, initial-scale=1.0" + title= content_for?(:title) ? yield(:title) : "Qrammer" + = csrf_meta_tags + + /! Le HTML5 shim, for IE6-8 support of HTML elements + /[if lt IE 9] + = javascript_include_tag "http://html5shim.googlecode.com/svn/trunk/html5.js" + = stylesheet_link_tag "application", :media => "all" + = stylesheet_link_tag "phone/application", :media => "all" + link href="images/apple-touch-icon-144x144.png" rel="apple-touch-icon-precomposed" sizes="144x144" + link href="images/apple-touch-icon-114x114.png" rel="apple-touch-icon-precomposed" sizes="114x114" + link href="images/apple-touch-icon-72x72.png" rel="apple-touch-icon-precomposed" sizes="72x72" + link href="images/apple-touch-icon.png" rel="apple-touch-icon-precomposed" + link href="images/favicon.ico" rel="shortcut icon" + javascript: + var active_list_id = #{session[:active_list_id] ? "'#{session[:active_list_id]}'" : 'null'}; + + body + .navbar.navbar-fixed-top + .navbar-inner + .container + a.btn.btn-navbar data-target=".nav-collapse" data-toggle="collapse" + span.icon-bar + span.icon-bar + span.icon-bar + a.brand href=phone_root_path Qrammer + .container.nav-collapse + ul.nav#top-navigation-list + li= link_to 'View history', user_history_path + + .container + + .content + - if flash[:alert].present? + .alert.alert-error + a.close data-dismiss="alert" × + div= flash[:alert] + - if flash[:notice].present? + .alert.alert-success + a.close data-dismiss="alert" × + div= flash[:notice] + .row + .span12 + = yield + /! + Javascripts + \================================================== + /! Placed at the end of the document so the pages load faster + = javascript_include_tag "application" + = yield :footer diff --git a/app/views/layouts/tablet.html.slim b/app/views/layouts/tablet.html.slim new file mode 100644 index 00000000..0ced2b9a --- /dev/null +++ b/app/views/layouts/tablet.html.slim @@ -0,0 +1,56 @@ +doctype html +html lang="en" + head + meta charset="utf-8" + meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" + meta name="viewport" content="width=device-width, initial-scale=1.0" + title= content_for?(:title) ? yield(:title) : "Qrammer" + = csrf_meta_tags + + /! Le HTML5 shim, for IE6-8 support of HTML elements + /[if lt IE 9] + = javascript_include_tag "http://html5shim.googlecode.com/svn/trunk/html5.js" + = stylesheet_link_tag "application", :media => "all" + = stylesheet_link_tag "phone/application", :media => "all" + link href="images/apple-touch-icon-144x144.png" rel="apple-touch-icon-precomposed" sizes="144x144" + link href="images/apple-touch-icon-114x114.png" rel="apple-touch-icon-precomposed" sizes="114x114" + link href="images/apple-touch-icon-72x72.png" rel="apple-touch-icon-precomposed" sizes="72x72" + link href="images/apple-touch-icon.png" rel="apple-touch-icon-precomposed" + link href="images/favicon.ico" rel="shortcut icon" + javascript: + var active_list_id = #{session[:active_list_id] ? "'#{session[:active_list_id]}'" : 'null'}; + + body + .navbar.navbar-fixed-top.navbar-inverse + .navbar-inner + .container + a.btn.btn-navbar data-target=".nav-collapse" data-toggle="collapse" + span.icon-bar + span.icon-bar + span.icon-bar + a.brand href=supplier_root_path Qrammer + .container.nav-collapse-disabled + ul.nav#top-navigation-list + li= link_to t('supplier.menu.active_orders', orders: Order.model_name.human_plural), supplier_orders_path + li= link_to t('supplier.menu.active_lists', lists: List.model_name.human_plural), supplier_lists_path + + .container + + .content + - if flash[:alert].present? + .alert.alert-error + a.close data-dismiss="alert" × + div= flash[:alert] + - if flash[:notice].present? + .alert.alert-success + a.close data-dismiss="alert" × + div= flash[:notice] + .row + .span12 + = yield + /! + Javascripts + \================================================== + /! Placed at the end of the document so the pages load faster + = javascript_include_tag "application" + = yield :footer diff --git a/app/views/suppliers/active_lists.html.slim b/app/views/suppliers/active_lists.html.slim index d3b6b082..1f5ad339 100644 --- a/app/views/suppliers/active_lists.html.slim +++ b/app/views/suppliers/active_lists.html.slim @@ -1,7 +1,8 @@ .page-header= title 'Active lists' -table#active-lists-table.table +table#active-lists-table.table.table-striped thead tr + th.status-icons th.number Table number th.currency Price th.actions diff --git a/app/views/suppliers/active_order_list.html.slim b/app/views/suppliers/active_orders.html.slim similarity index 65% rename from app/views/suppliers/active_order_list.html.slim rename to app/views/suppliers/active_orders.html.slim index e9e37c6c..1a81fcde 100644 --- a/app/views/suppliers/active_order_list.html.slim +++ b/app/views/suppliers/active_orders.html.slim @@ -10,7 +10,7 @@ table#active-orders-table.table - content_for :footer do javascript: jQuery(function(){ - Qrammer.load_active_order_list('#{@supplier.id}') - setInterval( "Qrammer.load_active_order_list('#{@supplier.id}')", 7500); + Qrammer.load_active_orders('#{@supplier.id}') + setInterval( "Qrammer.load_active_orders('#{@supplier.id}')", 7500); }); diff --git a/config/environments/development.rb b/config/environments/development.rb index 02d7998c..011eb157 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -5,6 +5,13 @@ Qrammer::Application.configure do # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false + silence_warnings do + begin + require 'pry' + IRB = Pry + rescue LoadError + end + end # Log error messages when you accidentally call methods on nil. config.whiny_nils = true diff --git a/config/locales/en.yml b/config/locales/en.yml index 81b22893..573220a0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -43,3 +43,6 @@ en: list: Lists product: Products product_category: Product categories + supplier: + menu: + active_lists: Active %{lists} diff --git a/config/routes.rb b/config/routes.rb index ed62b2f1..a629d80f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,7 +14,7 @@ Qrammer::Application.routes.draw do resources :suppliers do member do get :product_list - get :active_order_list + get :active_orders get :active_lists end end @@ -29,6 +29,11 @@ Qrammer::Application.routes.draw do match "/:action", controller: 'dashboard' match '/view_active_list' => 'dashboard#view_active_list', as: :view_active_list + match '/phone_home' => 'dashboard#phone_home', as: :phone_root + match '/supplier_home' => 'dashboard#supplier_home', as: :supplier_root + match '/supplier_home' => 'dashboard#supplier_home', as: :supplier_orders + match '/supplier_lists' => 'dashboard#supplier_lists', as: :supplier_lists + match '/user_history' => 'dashboard#user_history', as: :user_history # The priority is based upon order of creation: # first created -> highest priority. diff --git a/spec/factories/list_factory.rb b/spec/factories/list_factory.rb new file mode 100644 index 00000000..81dfb3fb --- /dev/null +++ b/spec/factories/list_factory.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :list do + association :table + end +end diff --git a/spec/factories/supplier_factory.rb b/spec/factories/supplier_factory.rb new file mode 100644 index 00000000..d9ed20cd --- /dev/null +++ b/spec/factories/supplier_factory.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :supplier do + sequence(:name){|i| "Supplier #{i}"} + end +end diff --git a/spec/factories/table_factory.rb b/spec/factories/table_factory.rb new file mode 100644 index 00000000..b13d9555 --- /dev/null +++ b/spec/factories/table_factory.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :table do + number 22 + association :supplier + end +end diff --git a/spec/models/list_spec.rb b/spec/models/list_spec.rb new file mode 100644 index 00000000..a7968129 --- /dev/null +++ b/spec/models/list_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + + +describe List do + before :each do + @list = create :list + end + describe :as_json do + it 'should include _id in as_json serialization' do + @list.as_json.keys.map(&:to_sym).should include :_id + end + it 'should include table_number in as_json serialization' do + @list.as_json.keys.should include :table_number + end + end + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 00000000..d028ab1f --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,65 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV["RAILS_ENV"] ||= 'test' +require File.expand_path("../../config/environment", __FILE__) +require 'rspec/rails' +require 'rspec/autorun' + +# Requires supporting ruby files with custom matchers and macros, etc, +# in spec/support/ and its subdirectories. +Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} +#Dir[Rails.root.join("spec/factories/**/*.rb")].each {|f| require f } + +I18n.locale = :en +Devise.stretches = 1 +Capybara.default_driver = :selenium +RSpec.configure do |config| + # == Mock Framework + # + # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: + # + # config.mock_with :mocha + # config.mock_with :flexmock + # config.mock_with :rr + config.mock_with :rspec + config.include FactoryGirl::Syntax::Methods + config.include Devise::TestHelpers, :type => :controller + config.include EndWithMatcher + #config.use_transactional_fixtures = true + config.infer_base_class_for_anonymous_controllers = true + config.render_views = true + + # Use color in STDOUT + config.color_enabled = true + + # Use color not only in STDOUT but also in pagers and files + config.tty = true + + # Use the specified formatter + config.formatter = :documentation # :progress, :html, :textmate + + # 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 + + config.before :each do + CouchPotato.couchrest_database.recreate! + end + config.before :each, type: :request do + #Capybara.current_driver = :selenium + #sign_in_user_through_request + end + # If true, the base class of anonymous controllers will be inferred + # automatically. This will be the default behavior in future versions of + # rspec-rails. + #config.infer_base_class_for_anonymous_controllers = true + def sign_in_user_through_request + visit "/users/sign_in" + fill_in 'user[email]', with: @user.email + fill_in 'user[password]', with: @user.password + click_on 'Inloggen' + end +end diff --git a/spec/support/end_with_matcher.rb b/spec/support/end_with_matcher.rb new file mode 100644 index 00000000..3f45566b --- /dev/null +++ b/spec/support/end_with_matcher.rb @@ -0,0 +1,43 @@ +module EndWithMatcher + class EndWith + def initialize(expected) + @expected = expected + end + + def matches?(target) + @target = target + @target =~ /#{@expected}$/ + end + + def failure_message + "expected <#{to_string(@target)}> to " + + "end with <#{to_string(@expected)}>" + end + + def negative_failure_message + "expected <#{to_string(@target)}> not to " + + "end with <#{to_string(@expected)}>" + end + + # Returns string representation of an object. + def to_string(value) + # indicate a nil + if value.nil? + 'nil' + end + + # join arrays + if value.class == Array + return value.join(", ") + end + + # otherwise return to_s() instead of inspect() + return value.to_s + end + end + + # Actual matcher that is exposed. + def end_with(expected) + EndWith.new(expected) + end +end