From a1ad32f20b99908ca736eae2dca19efc62c27b52 Mon Sep 17 00:00:00 2001 From: Kosuke Tanabe Date: Fri, 6 Jan 2012 04:23:16 +0900 Subject: [PATCH] added spec files --- .gitignore | 7 +- .rspec | 1 + Gemfile | 1 + Rakefile | 12 +- app/controllers/barcodes_controller.rb | 6 - app/models/barcode.rb | 6 +- config/locales/translation_en.yml | 9 + config/locales/translation_ja.yml | 9 + db/migrate/20081108112016_create_barcodes.rb | 14 + enju_barcode.gemspec | 7 +- lib/enju_barcode/engine.rb | 4 + script/rails | 2 +- spec/controllers/barcodes_controller_spec.rb | 479 ++++++++++++++++++ spec/dummy/Rakefile | 7 + .../app/assets/javascripts/application.js | 9 + .../app/assets/stylesheets/application.css | 7 + .../app/controllers/application_controller.rb | 62 +++ spec/dummy/app/helpers/application_helper.rb | 2 + spec/dummy/app/mailers/.gitkeep | 0 spec/dummy/app/models/.gitkeep | 0 spec/dummy/app/models/ability.rb | 18 + spec/dummy/app/models/role.rb | 5 + spec/dummy/app/models/user.rb | 28 + spec/dummy/app/models/user_has_role.rb | 4 + .../app/views/layouts/application.html.erb | 14 + spec/dummy/app/views/page/403.html.erb | 9 + spec/dummy/app/views/page/403.xml.erb | 4 + spec/dummy/app/views/page/404.html.erb | 9 + spec/dummy/app/views/page/404.xml.erb | 4 + spec/dummy/config.ru | 4 + spec/dummy/config/application.rb | 45 ++ spec/dummy/config/boot.rb | 10 + spec/dummy/config/database.yml | 25 + spec/dummy/config/environment.rb | 5 + spec/dummy/config/environments/development.rb | 30 ++ spec/dummy/config/environments/production.rb | 60 +++ spec/dummy/config/environments/test.rb | 39 ++ .../initializers/backtrace_silencers.rb | 7 + spec/dummy/config/initializers/devise.rb | 209 ++++++++ spec/dummy/config/initializers/inflections.rb | 10 + spec/dummy/config/initializers/mime_types.rb | 6 + .../dummy/config/initializers/secret_token.rb | 7 + .../config/initializers/session_store.rb | 8 + .../config/initializers/wrap_parameters.rb | 14 + spec/dummy/config/locales/en.yml | 5 + spec/dummy/config/routes.rb | 60 +++ .../db/migrate/20111201121844_create_roles.rb | 12 + .../db/migrate/20111201155456_create_users.rb | 13 + .../20111201155513_add_devise_to_users.rb | 31 ++ .../20111201163718_create_user_has_roles.rb | 10 + spec/dummy/db/schema.rb | 62 +++ spec/dummy/lib/assets/.gitkeep | 0 spec/dummy/log/.gitkeep | 0 spec/dummy/public/404.html | 26 + spec/dummy/public/422.html | 26 + spec/dummy/public/500.html | 26 + spec/dummy/public/favicon.ico | 0 spec/dummy/script/rails | 6 + spec/factories/barcode.rb | 5 + spec/factories/user.rb | 31 ++ spec/fixtures/roles.yml | 21 + spec/fixtures/user_has_roles.yml | 41 ++ spec/fixtures/users.yml | 69 +++ spec/spec_helper.rb | 32 ++ spec/support/controller_macros.rb | 48 ++ spec/support/devise.rb | 4 + 66 files changed, 1732 insertions(+), 14 deletions(-) create mode 100644 .rspec create mode 100644 config/locales/translation_en.yml create mode 100644 config/locales/translation_ja.yml create mode 100644 db/migrate/20081108112016_create_barcodes.rb create mode 100644 spec/controllers/barcodes_controller_spec.rb create mode 100644 spec/dummy/Rakefile create mode 100644 spec/dummy/app/assets/javascripts/application.js create mode 100644 spec/dummy/app/assets/stylesheets/application.css create mode 100644 spec/dummy/app/controllers/application_controller.rb create mode 100644 spec/dummy/app/helpers/application_helper.rb create mode 100644 spec/dummy/app/mailers/.gitkeep create mode 100644 spec/dummy/app/models/.gitkeep create mode 100644 spec/dummy/app/models/ability.rb create mode 100644 spec/dummy/app/models/role.rb create mode 100644 spec/dummy/app/models/user.rb create mode 100644 spec/dummy/app/models/user_has_role.rb create mode 100644 spec/dummy/app/views/layouts/application.html.erb create mode 100644 spec/dummy/app/views/page/403.html.erb create mode 100644 spec/dummy/app/views/page/403.xml.erb create mode 100644 spec/dummy/app/views/page/404.html.erb create mode 100644 spec/dummy/app/views/page/404.xml.erb create mode 100644 spec/dummy/config.ru create mode 100644 spec/dummy/config/application.rb create mode 100644 spec/dummy/config/boot.rb create mode 100644 spec/dummy/config/database.yml create mode 100644 spec/dummy/config/environment.rb create mode 100644 spec/dummy/config/environments/development.rb create mode 100644 spec/dummy/config/environments/production.rb create mode 100644 spec/dummy/config/environments/test.rb create mode 100644 spec/dummy/config/initializers/backtrace_silencers.rb create mode 100644 spec/dummy/config/initializers/devise.rb create mode 100644 spec/dummy/config/initializers/inflections.rb create mode 100644 spec/dummy/config/initializers/mime_types.rb create mode 100644 spec/dummy/config/initializers/secret_token.rb create mode 100644 spec/dummy/config/initializers/session_store.rb create mode 100644 spec/dummy/config/initializers/wrap_parameters.rb create mode 100644 spec/dummy/config/locales/en.yml create mode 100644 spec/dummy/config/routes.rb create mode 100644 spec/dummy/db/migrate/20111201121844_create_roles.rb create mode 100644 spec/dummy/db/migrate/20111201155456_create_users.rb create mode 100644 spec/dummy/db/migrate/20111201155513_add_devise_to_users.rb create mode 100644 spec/dummy/db/migrate/20111201163718_create_user_has_roles.rb create mode 100644 spec/dummy/db/schema.rb create mode 100644 spec/dummy/lib/assets/.gitkeep create mode 100644 spec/dummy/log/.gitkeep create mode 100644 spec/dummy/public/404.html create mode 100644 spec/dummy/public/422.html create mode 100644 spec/dummy/public/500.html create mode 100644 spec/dummy/public/favicon.ico create mode 100755 spec/dummy/script/rails create mode 100644 spec/factories/barcode.rb create mode 100644 spec/factories/user.rb create mode 100644 spec/fixtures/roles.yml create mode 100644 spec/fixtures/user_has_roles.yml create mode 100644 spec/fixtures/users.yml create mode 100644 spec/spec_helper.rb create mode 100644 spec/support/controller_macros.rb create mode 100644 spec/support/devise.rb diff --git a/.gitignore b/.gitignore index 1463de6..cdb3fc9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,9 @@ log/*.log pkg/ test/dummy/db/*.sqlite3 test/dummy/log/*.log -test/dummy/tmp/ \ No newline at end of file +test/dummy/tmp/ +spec/dummy/db/*.sqlite3 +spec/dummy/log/*.log +spec/dummy/solr/ +spec/dummy/tmp/ +spec/cassette_library/ diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..53607ea --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--colour diff --git a/Gemfile b/Gemfile index 021ef49..93c0d3c 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ gemspec # your gemspec. These might include edge Rails or gems from your path or # Git. Remember to move these dependencies to your gemspec before releasing # your gem to rubygems.org. +gem 'factory_girl_rails', '~> 1.4' # To use debugger # gem 'ruby-debug19', :require => 'ruby-debug' diff --git a/Rakefile b/Rakefile index bef8fb1..1207eb8 100644 --- a/Rakefile +++ b/Rakefile @@ -14,13 +14,13 @@ end RDoc::Task.new(:rdoc) do |rdoc| rdoc.rdoc_dir = 'rdoc' - rdoc.title = 'EnjuBarcode' + rdoc.title = 'EnjuPurchaseRequest' rdoc.options << '--line-numbers' rdoc.rdoc_files.include('README.rdoc') rdoc.rdoc_files.include('lib/**/*.rb') end -APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__) +APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__) load 'rails/tasks/engine.rake' @@ -35,5 +35,11 @@ Rake::TestTask.new(:test) do |t| t.verbose = false end +require 'rspec/core' +require 'rspec/core/rake_task' -task :default => :test +RSpec::Core::RakeTask.new(:spec) do |spec| + spec.pattern = FileList['spec/**/*_spec.rb'] +end + +task :default => :spec diff --git a/app/controllers/barcodes_controller.rb b/app/controllers/barcodes_controller.rb index 2d9c532..97c7d57 100644 --- a/app/controllers/barcodes_controller.rb +++ b/app/controllers/barcodes_controller.rb @@ -22,8 +22,6 @@ def index # GET /barcodes/1 # GET /barcodes/1.json def show - @barcode = Barcode.find(params[:id]) - respond_to do |format| format.html # show.html.erb format.json { render :json => @barcode } @@ -44,7 +42,6 @@ def new # GET /barcodes/1/edit def edit - @barcode = Barcode.find(params[:id]) end # POST /barcodes @@ -67,8 +64,6 @@ def create # PUT /barcodes/1 # PUT /barcodes/1.json def update - @barcode = Barcode.find(params[:id]) - respond_to do |format| if @barcode.update_attributes(params[:barcode]) flash[:notice] = t('controller.successfully_updated', :model => t('activerecord.models.barcode')) @@ -84,7 +79,6 @@ def update # DELETE /barcodes/1 # DELETE /barcodes/1.json def destroy - @barcode = Barcode.find(params[:id]) @barcode.destroy respond_to do |format| diff --git a/app/models/barcode.rb b/app/models/barcode.rb index 14f5ea7..db285b4 100644 --- a/app/models/barcode.rb +++ b/app/models/barcode.rb @@ -1,3 +1,7 @@ +# TODO: Codarbar support +require 'barby/barcode/code_39' +require 'barby/outputter/svg_outputter' + class Barcode < ActiveRecord::Base belongs_to :barcodable, :polymorphic => true @@ -11,7 +15,7 @@ def self.per_page end def generate_barcode - self.data = Barby::Code128B.new(self.code_word).to_svg(:width => 150, :height => 70) + self.data = Barby::Code39.new(code_word).to_svg(:width => 150, :height => 70) end def is_readable_by(user, parent = nil) diff --git a/config/locales/translation_en.yml b/config/locales/translation_en.yml new file mode 100644 index 0000000..1595682 --- /dev/null +++ b/config/locales/translation_en.yml @@ -0,0 +1,9 @@ +ja: + activerecord: + models: + barcode: "Barcode" + + attributes: + barcode: + code_word: "Code word" + data: "Data" diff --git a/config/locales/translation_ja.yml b/config/locales/translation_ja.yml new file mode 100644 index 0000000..6194104 --- /dev/null +++ b/config/locales/translation_ja.yml @@ -0,0 +1,9 @@ +ja: + activerecord: + models: + barcode: バーコード + + attributes: + barcode: + code_word: コードワード + data: データ diff --git a/db/migrate/20081108112016_create_barcodes.rb b/db/migrate/20081108112016_create_barcodes.rb new file mode 100644 index 0000000..5d82ded --- /dev/null +++ b/db/migrate/20081108112016_create_barcodes.rb @@ -0,0 +1,14 @@ +class CreateBarcodes < ActiveRecord::Migration + def self.up + create_table :barcodes do |t| + t.string :code_word + t.binary :data + + t.timestamps + end + end + + def self.down + drop_table :barcodes + end +end diff --git a/enju_barcode.gemspec b/enju_barcode.gemspec index 45b87a1..ef07104 100644 --- a/enju_barcode.gemspec +++ b/enju_barcode.gemspec @@ -14,11 +14,14 @@ Gem::Specification.new do |s| s.description = "barcode generator for Next-L Enju" s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"] - s.test_files = Dir["test/**/*"] + s.test_files = Dir["spec/**/*"] - s.add_dependency "rails", "~> 3" + s.add_dependency "rails", "~> 3.0" s.add_dependency "barby", "~> 0.5" s.add_dependency "rqrcode" + s.add_dependency "devise" + s.add_dependency "cancan" + s.add_dependency "will_paginate" s.add_development_dependency "sqlite3" s.add_development_dependency "rspec-rails" diff --git a/lib/enju_barcode/engine.rb b/lib/enju_barcode/engine.rb index 94edc59..60bd703 100644 --- a/lib/enju_barcode/engine.rb +++ b/lib/enju_barcode/engine.rb @@ -1,3 +1,7 @@ +require 'devise' +require 'cancan' +require 'will_paginate' + module EnjuBarcode class Engine < Rails::Engine end diff --git a/script/rails b/script/rails index e323e44..4309856 100755 --- a/script/rails +++ b/script/rails @@ -3,4 +3,4 @@ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. ENGINE_PATH = File.expand_path('../..', __FILE__) -load File.expand_path('../../test/dummy/script/rails', __FILE__) +load File.expand_path('../../spec/dummy/script/rails', __FILE__) diff --git a/spec/controllers/barcodes_controller_spec.rb b/spec/controllers/barcodes_controller_spec.rb new file mode 100644 index 0000000..6b6ad55 --- /dev/null +++ b/spec/controllers/barcodes_controller_spec.rb @@ -0,0 +1,479 @@ +require 'spec_helper' + +describe BarcodesController do + fixtures :all + + describe "GET index" do + before(:each) do + FactoryGirl.create(:barcode) + end + + describe "When logged in as Administrator" do + before(:each) do + sign_in FactoryGirl.create(:admin) + end + + it "assigns all barcodes as @barcodes" do + get :index + assigns(:barcodes).should eq(Barcode.all) + end + end + + describe "When logged in as Librarian" do + before(:each) do + sign_in FactoryGirl.create(:librarian) + end + + it "assigns all barcodes as @barcodes" do + get :index + assigns(:barcodes).should eq(Barcode.all) + end + end + + describe "When logged in as User" do + before(:each) do + sign_in FactoryGirl.create(:user) + end + + it "should be forbidden" do + get :index + assigns(:barcodes).should be_empty + response.should be_forbidden + end + end + + describe "When not logged in" do + it "assigns all barcodes as @barcodes" do + get :index + assigns(:barcodes).should be_empty + response.should redirect_to(new_user_session_url) + end + end + end + + describe "GET show" do + describe "When logged in as Administrator" do + before(:each) do + sign_in FactoryGirl.create(:admin) + end + + it "assigns the requested barcode as @barcode" do + barcode = FactoryGirl.create(:barcode) + get :show, :id => barcode.id + assigns(:barcode).should eq(barcode) + end + end + + describe "When logged in as Librarian" do + before(:each) do + sign_in FactoryGirl.create(:librarian) + end + + it "assigns the requested barcode as @barcode" do + barcode = FactoryGirl.create(:barcode) + get :show, :id => barcode.id + assigns(:barcode).should eq(barcode) + end + end + + describe "When logged in as User" do + before(:each) do + sign_in FactoryGirl.create(:user) + end + + it "assigns the requested barcode as @barcode" do + barcode = FactoryGirl.create(:barcode) + get :show, :id => barcode.id + assigns(:barcode).should eq(barcode) + end + end + + describe "When not logged in" do + it "assigns the requested barcode as @barcode" do + barcode = FactoryGirl.create(:barcode) + get :show, :id => barcode.id + assigns(:barcode).should eq(barcode) + end + end + end + + describe "GET new" do + describe "When logged in as Administrator" do + before(:each) do + sign_in FactoryGirl.create(:admin) + end + + it "assigns the requested barcode as @barcode" do + get :new + assigns(:barcode).should_not be_valid + response.should be_success + end + end + + describe "When logged in as Librarian" do + before(:each) do + sign_in FactoryGirl.create(:librarian) + end + + it "assigns the requested barcode as @barcode" do + get :new + assigns(:barcode).should_not be_valid + response.should be_success + end + end + + describe "When logged in as User" do + before(:each) do + sign_in FactoryGirl.create(:user) + end + + it "should not assign the requested barcode as @barcode" do + get :new + assigns(:barcode).should_not be_valid + response.should be_forbidden + end + end + + describe "When not logged in" do + it "should not assign the requested barcode as @barcode" do + get :new + assigns(:barcode).should_not be_valid + response.should redirect_to(new_user_session_url) + end + end + end + + describe "GET edit" do + describe "When logged in as Administrator" do + before(:each) do + sign_in FactoryGirl.create(:admin) + end + + it "assigns the requested barcode as @barcode" do + barcode = FactoryGirl.create(:barcode) + get :edit, :id => barcode.id + assigns(:barcode).should eq(barcode) + end + end + + describe "When logged in as Librarian" do + before(:each) do + sign_in FactoryGirl.create(:librarian) + end + + it "assigns the requested barcode as @barcode" do + barcode = FactoryGirl.create(:barcode) + get :edit, :id => barcode.id + assigns(:barcode).should eq(barcode) + end + end + + describe "When logged in as User" do + before(:each) do + sign_in FactoryGirl.create(:user) + end + + it "assigns the requested barcode as @barcode" do + barcode = FactoryGirl.create(:barcode) + get :edit, :id => barcode.id + response.should be_forbidden + end + end + + describe "When not logged in" do + it "should not assign the requested barcode as @barcode" do + barcode = FactoryGirl.create(:barcode) + get :edit, :id => barcode.id + response.should redirect_to(new_user_session_url) + end + end + end + + describe "POST create" do + before(:each) do + @attrs = FactoryGirl.attributes_for(:barcode) + @invalid_attrs = {:code_word => ''} + end + + describe "When logged in as Administrator" do + before(:each) do + sign_in FactoryGirl.create(:admin) + end + + describe "with valid params" do + it "assigns a newly created barcode as @barcode" do + post :create, :barcode => @attrs + assigns(:barcode).should be_valid + end + + it "redirects to the created patron" do + post :create, :barcode => @attrs + response.should redirect_to(assigns(:barcode)) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved barcode as @barcode" do + post :create, :barcode => @invalid_attrs + assigns(:barcode).should_not be_valid + end + + it "re-renders the 'new' template" do + post :create, :barcode => @invalid_attrs + response.should render_template("new") + end + end + end + + describe "When logged in as Librarian" do + before(:each) do + sign_in FactoryGirl.create(:librarian) + end + + describe "with valid params" do + it "assigns a newly created barcode as @barcode" do + post :create, :barcode => @attrs + assigns(:barcode).should be_valid + end + + it "redirects to the created patron" do + post :create, :barcode => @attrs + response.should redirect_to(assigns(:barcode)) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved barcode as @barcode" do + post :create, :barcode => @invalid_attrs + assigns(:barcode).should_not be_valid + end + + it "re-renders the 'new' template" do + post :create, :barcode => @invalid_attrs + response.should render_template("new") + end + end + end + + describe "When logged in as User" do + before(:each) do + sign_in FactoryGirl.create(:user) + end + + describe "with valid params" do + it "assigns a newly created barcode as @barcode" do + post :create, :barcode => @attrs + assigns(:barcode).should be_valid + end + + it "should be forbidden" do + post :create, :barcode => @attrs + response.should be_forbidden + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved barcode as @barcode" do + post :create, :barcode => @invalid_attrs + assigns(:barcode).should_not be_valid + end + + it "should be forbidden" do + post :create, :barcode => @invalid_attrs + response.should be_forbidden + end + end + end + + describe "When not logged in" do + describe "with valid params" do + it "assigns a newly created barcode as @barcode" do + post :create, :barcode => @attrs + assigns(:barcode).should be_valid + end + + it "should be forbidden" do + post :create, :barcode => @attrs + response.should redirect_to(new_user_session_url) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved barcode as @barcode" do + post :create, :barcode => @invalid_attrs + assigns(:barcode).should_not be_valid + end + + it "should be forbidden" do + post :create, :barcode => @invalid_attrs + response.should redirect_to(new_user_session_url) + end + end + end + end + + describe "PUT update" do + before(:each) do + @barcode = FactoryGirl.create(:barcode) + @attrs = FactoryGirl.attributes_for(:barcode) + @invalid_attrs = {:code_word => ''} + end + + describe "When logged in as Administrator" do + before(:each) do + sign_in FactoryGirl.create(:admin) + end + + describe "with valid params" do + it "updates the requested barcode" do + put :update, :id => @barcode.id, :barcode => @attrs + end + + it "assigns the requested barcode as @barcode" do + put :update, :id => @barcode.id, :barcode => @attrs + assigns(:barcode).should eq(@barcode) + response.should redirect_to(@barcode) + end + end + + describe "with invalid params" do + it "assigns the requested barcode as @barcode" do + put :update, :id => @barcode.id, :barcode => @invalid_attrs + response.should render_template("edit") + end + end + end + + describe "When logged in as Librarian" do + before(:each) do + sign_in FactoryGirl.create(:librarian) + end + + describe "with valid params" do + it "updates the requested barcode" do + put :update, :id => @barcode.id, :barcode => @attrs + end + + it "assigns the requested barcode as @barcode" do + put :update, :id => @barcode.id, :barcode => @attrs + assigns(:barcode).should eq(@barcode) + response.should redirect_to(@barcode) + end + end + + describe "with invalid params" do + it "assigns the requested barcode as @barcode" do + put :update, :id => @barcode.id, :barcode => @invalid_attrs + response.should render_template("edit") + end + end + end + + describe "When logged in as User" do + before(:each) do + sign_in FactoryGirl.create(:user) + end + + describe "with valid params" do + it "updates the requested barcode" do + put :update, :id => @barcode.id, :barcode => @attrs + end + + it "assigns the requested barcode as @barcode" do + put :update, :id => @barcode.id, :barcode => @attrs + assigns(:barcode).should eq(@barcode) + response.should be_forbidden + end + end + + describe "with invalid params" do + it "assigns the requested barcode as @barcode" do + put :update, :id => @barcode.id, :barcode => @invalid_attrs + response.should be_forbidden + end + end + end + + describe "When not logged in" do + describe "with valid params" do + it "updates the requested barcode" do + put :update, :id => @barcode.id, :barcode => @attrs + end + + it "should be forbidden" do + put :update, :id => @barcode.id, :barcode => @attrs + response.should redirect_to(new_user_session_url) + end + end + + describe "with invalid params" do + it "assigns the requested barcode as @barcode" do + put :update, :id => @barcode.id, :barcode => @invalid_attrs + response.should redirect_to(new_user_session_url) + end + end + end + end + + describe "DELETE destroy" do + before(:each) do + @barcode = FactoryGirl.create(:barcode) + end + + describe "When logged in as Administrator" do + before(:each) do + sign_in FactoryGirl.create(:admin) + end + + it "destroys the requested barcode" do + delete :destroy, :id => @barcode.id + end + + it "redirects to the barcodes list" do + delete :destroy, :id => @barcode.id + response.should redirect_to(barcodes_url) + end + end + + describe "When logged in as Librarian" do + before(:each) do + sign_in FactoryGirl.create(:librarian) + end + + it "destroys the requested barcode" do + delete :destroy, :id => @barcode.id + end + + it "redirects to the barcodes list" do + delete :destroy, :id => @barcode.id + response.should redirect_to(barcodes_url) + end + end + + describe "When logged in as User" do + before(:each) do + sign_in FactoryGirl.create(:user) + end + + it "destroys the requested barcode" do + delete :destroy, :id => @barcode.id + end + + it "should be forbidden" do + delete :destroy, :id => @barcode.id + response.should be_forbidden + end + end + + describe "When not logged in" do + it "destroys the requested barcode" do + delete :destroy, :id => @barcode.id + end + + it "should be forbidden" do + delete :destroy, :id => @barcode.id + response.should redirect_to(new_user_session_url) + end + end + end +end diff --git a/spec/dummy/Rakefile b/spec/dummy/Rakefile new file mode 100644 index 0000000..3645852 --- /dev/null +++ b/spec/dummy/Rakefile @@ -0,0 +1,7 @@ +#!/usr/bin/env rake +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require File.expand_path('../config/application', __FILE__) + +Dummy::Application.load_tasks diff --git a/spec/dummy/app/assets/javascripts/application.js b/spec/dummy/app/assets/javascripts/application.js new file mode 100644 index 0000000..37c7bfc --- /dev/null +++ b/spec/dummy/app/assets/javascripts/application.js @@ -0,0 +1,9 @@ +// This is a manifest file that'll be compiled into including all the files listed below. +// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically +// be included in the compiled file accessible from http://example.com/assets/application.js +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// the compiled file. +// +//= require jquery +//= require jquery_ujs +//= require_tree . diff --git a/spec/dummy/app/assets/stylesheets/application.css b/spec/dummy/app/assets/stylesheets/application.css new file mode 100644 index 0000000..fc25b57 --- /dev/null +++ b/spec/dummy/app/assets/stylesheets/application.css @@ -0,0 +1,7 @@ +/* + * This is a manifest file that'll automatically include all the stylesheets available in this directory + * and any sub-directories. 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_tree . +*/ \ No newline at end of file diff --git a/spec/dummy/app/controllers/application_controller.rb b/spec/dummy/app/controllers/application_controller.rb new file mode 100644 index 0000000..78e7f6f --- /dev/null +++ b/spec/dummy/app/controllers/application_controller.rb @@ -0,0 +1,62 @@ +class ApplicationController < ActionController::Base + protect_from_forgery + + rescue_from CanCan::AccessDenied, :with => :render_403 + rescue_from ActiveRecord::RecordNotFound, :with => :render_404 + + before_filter :set_locale + + private + def render_403 + return if performed? + if user_signed_in? + respond_to do |format| + format.html {render :template => 'page/403', :status => 403} + format.xml {render :template => 'page/403', :status => 403} + format.json + end + else + respond_to do |format| + format.html {redirect_to new_user_session_url} + format.xml {render :template => 'page/403', :status => 403} + format.json + end + end + end + + def render_404 + return if performed? + respond_to do |format| + format.html {render :template => 'page/404', :status => 404} + format.xml {render :template => 'page/404', :status => 404} + format.json + end + end + + def set_locale + if params[:locale] + unless I18n.available_locales.include?(params[:locale].to_s.intern) + raise InvalidLocaleError + end + end + if user_signed_in? + locale = params[:locale] || session[:locale] || current_user.locale.try(:to_sym) + else + locale = params[:locale] || session[:locale] + end + if locale + I18n.locale = @locale = session[:locale] = locale.to_sym + else + I18n.locale = @locale = session[:locale] = I18n.default_locale + end + rescue InvalidLocaleError + @locale = I18n.default_locale + end + + def access_denied + raise CanCan::AccessDenied + end +end + +class InvalidLocaleError < StandardError +end diff --git a/spec/dummy/app/helpers/application_helper.rb b/spec/dummy/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/spec/dummy/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/spec/dummy/app/mailers/.gitkeep b/spec/dummy/app/mailers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/app/models/.gitkeep b/spec/dummy/app/models/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/app/models/ability.rb b/spec/dummy/app/models/ability.rb new file mode 100644 index 0000000..bdb8355 --- /dev/null +++ b/spec/dummy/app/models/ability.rb @@ -0,0 +1,18 @@ +class Ability + include CanCan::Ability + + def initialize(user) + case user.try(:role).try(:name) + when 'Administrator' + can :manage, [ + Barcode + ] + when 'Librarian' + can :manage, [ + Barcode + ] + else + can :show, Barcode + end + end +end diff --git a/spec/dummy/app/models/role.rb b/spec/dummy/app/models/role.rb new file mode 100644 index 0000000..202a873 --- /dev/null +++ b/spec/dummy/app/models/role.rb @@ -0,0 +1,5 @@ +class Role < ActiveRecord::Base + def self.default_role + Role.where(:name => 'Guest').first + end +end diff --git a/spec/dummy/app/models/user.rb b/spec/dummy/app/models/user.rb new file mode 100644 index 0000000..991e243 --- /dev/null +++ b/spec/dummy/app/models/user.rb @@ -0,0 +1,28 @@ +class User < ActiveRecord::Base + # Include default devise modules. Others available are: + # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable + + # Setup accessible (or protected) attributes for your model + attr_accessible :email, :password, :password_confirmation, :remember_me + + has_one :user_has_role + has_one :role, :through => :user_has_role + belongs_to :required_role, :class_name => 'Role', :foreign_key => 'required_role_id' + has_many :purchase_requests + has_many :order_lists + + def has_role?(role_in_question) + return false unless role + return true if role.name == role_in_question + case role.name + when 'Administrator' + return true + when 'Librarian' + return true if role_in_question == 'User' + else + false + end + end +end diff --git a/spec/dummy/app/models/user_has_role.rb b/spec/dummy/app/models/user_has_role.rb new file mode 100644 index 0000000..b3fc324 --- /dev/null +++ b/spec/dummy/app/models/user_has_role.rb @@ -0,0 +1,4 @@ +class UserHasRole < ActiveRecord::Base + belongs_to :user + belongs_to :role +end diff --git a/spec/dummy/app/views/layouts/application.html.erb b/spec/dummy/app/views/layouts/application.html.erb new file mode 100644 index 0000000..9a8a761 --- /dev/null +++ b/spec/dummy/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + Dummy + <%= stylesheet_link_tag "application" %> + <%= javascript_include_tag "application" %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/spec/dummy/app/views/page/403.html.erb b/spec/dummy/app/views/page/403.html.erb new file mode 100644 index 0000000..d260ba4 --- /dev/null +++ b/spec/dummy/app/views/page/403.html.erb @@ -0,0 +1,9 @@ +
+

<%= t('page.access_denied') -%>

+
+ <%= render 'page/search_form' %> +
+
+ + diff --git a/spec/dummy/app/views/page/403.xml.erb b/spec/dummy/app/views/page/403.xml.erb new file mode 100644 index 0000000..49b9eff --- /dev/null +++ b/spec/dummy/app/views/page/403.xml.erb @@ -0,0 +1,4 @@ + + + 403 + diff --git a/spec/dummy/app/views/page/404.html.erb b/spec/dummy/app/views/page/404.html.erb new file mode 100644 index 0000000..fe6d57b --- /dev/null +++ b/spec/dummy/app/views/page/404.html.erb @@ -0,0 +1,9 @@ +
+

<%= t('page.not_found') -%>

+
+ <%= render 'page/search_form' %> +
+
+ + diff --git a/spec/dummy/app/views/page/404.xml.erb b/spec/dummy/app/views/page/404.xml.erb new file mode 100644 index 0000000..69c3aa5 --- /dev/null +++ b/spec/dummy/app/views/page/404.xml.erb @@ -0,0 +1,4 @@ + + + 404 + diff --git a/spec/dummy/config.ru b/spec/dummy/config.ru new file mode 100644 index 0000000..1989ed8 --- /dev/null +++ b/spec/dummy/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Dummy::Application diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb new file mode 100644 index 0000000..84ab10f --- /dev/null +++ b/spec/dummy/config/application.rb @@ -0,0 +1,45 @@ +require File.expand_path('../boot', __FILE__) + +require 'rails/all' + +Bundler.require +require "enju_barcode" + +module Dummy + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Custom directories with classes and modules you want to be autoloadable. + # config.autoload_paths += %W(#{config.root}/extras) + + # Only load the plugins named here, in the order given (default is alphabetical). + # :all can be used as a placeholder for all plugins not explicitly named. + # config.plugins = [ :exception_notification, :ssl_requirement, :all ] + + # Activate observers that should always be running. + # config.active_record.observers = :cacher, :garbage_collector, :forum_observer + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. + # config.time_zone = 'Central Time (US & Canada)' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + # config.i18n.default_locale = :de + + # Configure the default encoding used in templates for Ruby 1.9. + config.encoding = "utf-8" + + # Configure sensitive parameters which will be filtered from the log file. + config.filter_parameters += [:password] + + # Enable the asset pipeline + config.assets.enabled = true + + # Version of your assets, change this if you want to expire all your assets + config.assets.version = '1.0' + end +end + diff --git a/spec/dummy/config/boot.rb b/spec/dummy/config/boot.rb new file mode 100644 index 0000000..eba0681 --- /dev/null +++ b/spec/dummy/config/boot.rb @@ -0,0 +1,10 @@ +require 'rubygems' +gemfile = File.expand_path('../../../../Gemfile', __FILE__) + +if File.exist?(gemfile) + ENV['BUNDLE_GEMFILE'] = gemfile + require 'bundler' + Bundler.setup +end + +$:.unshift File.expand_path('../../../../lib', __FILE__) \ No newline at end of file diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml new file mode 100644 index 0000000..51a4dd4 --- /dev/null +++ b/spec/dummy/config/database.yml @@ -0,0 +1,25 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +development: + adapter: sqlite3 + database: db/development.sqlite3 + pool: 5 + timeout: 5000 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + adapter: sqlite3 + database: db/test.sqlite3 + pool: 5 + timeout: 5000 + +production: + adapter: sqlite3 + database: db/production.sqlite3 + pool: 5 + timeout: 5000 diff --git a/spec/dummy/config/environment.rb b/spec/dummy/config/environment.rb new file mode 100644 index 0000000..3da5eb9 --- /dev/null +++ b/spec/dummy/config/environment.rb @@ -0,0 +1,5 @@ +# Load the rails application +require File.expand_path('../application', __FILE__) + +# Initialize the rails application +Dummy::Application.initialize! diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb new file mode 100644 index 0000000..95a50b9 --- /dev/null +++ b/spec/dummy/config/environments/development.rb @@ -0,0 +1,30 @@ +Dummy::Application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # In the development environment your application's code is reloaded on + # 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 + + # Log error messages when you accidentally call methods on nil. + config.whiny_nils = true + + # Show full error reports and disable caching + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger + config.active_support.deprecation = :log + + # Only use best-standards-support built into browsers + config.action_dispatch.best_standards_support = :builtin + + # Do not compress assets + config.assets.compress = false + + # Expands the lines which load the assets + config.assets.debug = true +end diff --git a/spec/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb new file mode 100644 index 0000000..ca2c588 --- /dev/null +++ b/spec/dummy/config/environments/production.rb @@ -0,0 +1,60 @@ +Dummy::Application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # Code is not reloaded between requests + config.cache_classes = true + + # Full error reports are disabled and caching is turned on + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Disable Rails's static asset server (Apache or nginx will already do this) + config.serve_static_assets = false + + # Compress JavaScripts and CSS + config.assets.compress = true + + # Don't fallback to assets pipeline if a precompiled asset is missed + config.assets.compile = false + + # Generate digests for assets URLs + config.assets.digest = true + + # Defaults to Rails.root.join("public/assets") + # config.assets.manifest = YOUR_PATH + + # Specifies the header that your server uses for sending files + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # See everything in the log (default is :info) + # config.log_level = :debug + + # Use a different logger for distributed setups + # config.logger = SyslogLogger.new + + # Use a different cache store in production + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server + # config.action_controller.asset_host = "http://assets.example.com" + + # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) + # config.assets.precompile += %w( search.js ) + + # Disable delivery errors, bad email addresses will be ignored + # config.action_mailer.raise_delivery_errors = false + + # Enable threaded mode + # config.threadsafe! + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation can not be found) + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners + config.active_support.deprecation = :notify +end diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb new file mode 100644 index 0000000..6810c91 --- /dev/null +++ b/spec/dummy/config/environments/test.rb @@ -0,0 +1,39 @@ +Dummy::Application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Configure static asset server for tests with Cache-Control for performance + config.serve_static_assets = true + config.static_cache_control = "public, max-age=3600" + + # Log error messages when you accidentally call methods on nil + config.whiny_nils = true + + # Show full error reports and disable caching + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Use SQL instead of Active Record's schema dumper when creating the test database. + # This is necessary if your schema can't be completely dumped by the schema dumper, + # like if you have constraints or database-specific column types + # config.active_record.schema_format = :sql + + # Print deprecation notices to the stderr + config.active_support.deprecation = :stderr +end diff --git a/spec/dummy/config/initializers/backtrace_silencers.rb b/spec/dummy/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/spec/dummy/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/spec/dummy/config/initializers/devise.rb b/spec/dummy/config/initializers/devise.rb new file mode 100644 index 0000000..b74aac1 --- /dev/null +++ b/spec/dummy/config/initializers/devise.rb @@ -0,0 +1,209 @@ +# Use this hook to configure devise mailer, warden hooks and so forth. +# Many of these configuration options can be set straight in your model. +Devise.setup do |config| + # ==> Mailer Configuration + # Configure the e-mail address which will be shown in Devise::Mailer, + # note that it will be overwritten if you use your own mailer class with default "from" parameter. + config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com" + + # Configure the class responsible to send e-mails. + # config.mailer = "Devise::Mailer" + + # ==> ORM configuration + # Load and configure the ORM. Supports :active_record (default) and + # :mongoid (bson_ext recommended) by default. Other ORMs may be + # available as additional gems. + require 'devise/orm/active_record' + + # ==> Configuration for any authentication mechanism + # Configure which keys are used when authenticating a user. The default is + # just :email. You can configure it to use [:username, :subdomain], so for + # authenticating a user, both parameters are required. Remember that those + # parameters are used only when authenticating and not when retrieving from + # session. If you need permissions, you should implement that in a before filter. + # You can also supply a hash where the value is a boolean determining whether + # or not authentication should be aborted when the value is not present. + # config.authentication_keys = [ :email ] + + # Configure parameters from the request object used for authentication. Each entry + # given should be a request method and it will automatically be passed to the + # find_for_authentication method and considered in your model lookup. For instance, + # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. + # The same considerations mentioned for authentication_keys also apply to request_keys. + # config.request_keys = [] + + # Configure which authentication keys should be case-insensitive. + # These keys will be downcased upon creating or modifying a user and when used + # to authenticate or find a user. Default is :email. + config.case_insensitive_keys = [ :email ] + + # Configure which authentication keys should have whitespace stripped. + # These keys will have whitespace before and after removed upon creating or + # modifying a user and when used to authenticate or find a user. Default is :email. + config.strip_whitespace_keys = [ :email ] + + # Tell if authentication through request.params is enabled. True by default. + # config.params_authenticatable = true + + # Tell if authentication through HTTP Basic Auth is enabled. False by default. + # config.http_authenticatable = false + + # If http headers should be returned for AJAX requests. True by default. + # config.http_authenticatable_on_xhr = true + + # The realm used in Http Basic Authentication. "Application" by default. + # config.http_authentication_realm = "Application" + + # It will change confirmation, password recovery and other workflows + # to behave the same regardless if the e-mail provided was right or wrong. + # Does not affect registerable. + # config.paranoid = true + + # ==> Configuration for :database_authenticatable + # For bcrypt, this is the cost for hashing the password and defaults to 10. If + # using other encryptors, it sets how many times you want the password re-encrypted. + # + # Limiting the stretches to just one in testing will increase the performance of + # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use + # a value less than 10 in other environments. + config.stretches = Rails.env.test? ? 1 : 10 + + # Setup a pepper to generate the encrypted password. + # config.pepper = "9c3e60feae3030ec50d52f408005d7083c980b028e24e96536c60829394fd7cf5e26fdfed03e48b756b8bbf16177d73cca8cc6d036b2e916c953faf8d2c0238c" + + # ==> Configuration for :confirmable + # A period that the user is allowed to access the website even without + # confirming his account. For instance, if set to 2.days, the user will be + # able to access the website for two days without confirming his account, + # access will be blocked just in the third day. Default is 0.days, meaning + # the user cannot access the website without confirming his account. + # config.confirm_within = 2.days + + # Defines which key will be used when confirming an account + # config.confirmation_keys = [ :email ] + + # ==> Configuration for :rememberable + # The time the user will be remembered without asking for credentials again. + # config.remember_for = 2.weeks + + # If true, a valid remember token can be re-used between multiple browsers. + # config.remember_across_browsers = true + + # If true, extends the user's remember period when remembered via cookie. + # config.extend_remember_period = false + + # If true, uses the password salt as remember token. This should be turned + # to false if you are not using database authenticatable. + config.use_salt_as_remember_token = true + + # Options to be passed to the created cookie. For instance, you can set + # :secure => true in order to force SSL only cookies. + # config.cookie_options = {} + + # ==> Configuration for :validatable + # Range for password length. Default is 6..128. + # config.password_length = 6..128 + + # Email regex used to validate email formats. It simply asserts that + # an one (and only one) @ exists in the given string. This is mainly + # to give user feedback and not to assert the e-mail validity. + # config.email_regexp = /\A[^@]+@[^@]+\z/ + + # ==> Configuration for :timeoutable + # The time you want to timeout the user session without activity. After this + # time the user will be asked for credentials again. Default is 30 minutes. + # config.timeout_in = 30.minutes + + # ==> Configuration for :lockable + # Defines which strategy will be used to lock an account. + # :failed_attempts = Locks an account after a number of failed attempts to sign in. + # :none = No lock strategy. You should handle locking by yourself. + # config.lock_strategy = :failed_attempts + + # Defines which key will be used when locking and unlocking an account + # config.unlock_keys = [ :email ] + + # Defines which strategy will be used to unlock an account. + # :email = Sends an unlock link to the user email + # :time = Re-enables login after a certain amount of time (see :unlock_in below) + # :both = Enables both strategies + # :none = No unlock strategy. You should handle unlocking by yourself. + # config.unlock_strategy = :both + + # Number of authentication tries before locking an account if lock_strategy + # is failed attempts. + # config.maximum_attempts = 20 + + # Time interval to unlock the account if :time is enabled as unlock_strategy. + # config.unlock_in = 1.hour + + # ==> Configuration for :recoverable + # + # Defines which key will be used when recovering the password for an account + # config.reset_password_keys = [ :email ] + + # Time interval you can reset your password with a reset password key. + # Don't put a too small interval or your users won't have the time to + # change their passwords. + config.reset_password_within = 2.hours + + # ==> Configuration for :encryptable + # Allow you to use another encryption algorithm besides bcrypt (default). You can use + # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, + # :authlogic_sha512 (then you should set stretches above to 20 for default behavior) + # and :restful_authentication_sha1 (then you should set stretches to 10, and copy + # REST_AUTH_SITE_KEY to pepper) + # config.encryptor = :sha512 + + # ==> Configuration for :token_authenticatable + # Defines name of the authentication token params key + # config.token_authentication_key = :auth_token + + # If true, authentication through token does not store user in session and needs + # to be supplied on each request. Useful if you are using the token as API token. + # config.stateless_token = false + + # ==> Scopes configuration + # Turn scoped views on. Before rendering "sessions/new", it will first check for + # "users/sessions/new". It's turned off by default because it's slower if you + # are using only default views. + # config.scoped_views = false + + # Configure the default scope given to Warden. By default it's the first + # devise role declared in your routes (usually :user). + # config.default_scope = :user + + # Configure sign_out behavior. + # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope). + # The default is true, which means any logout action will sign out all active scopes. + # config.sign_out_all_scopes = true + + # ==> Navigation configuration + # Lists the formats that should be treated as navigational. Formats like + # :html, should redirect to the sign in page when the user does not have + # access, but formats like :xml or :json, should return 401. + # + # If you have any extra navigational formats, like :iphone or :mobile, you + # should add them to the navigational formats lists. + # + # The :"*/*" and "*/*" formats below is required to match Internet + # Explorer requests. + # config.navigational_formats = [:"*/*", "*/*", :html] + + # The default HTTP method used to sign out a resource. Default is :delete. + config.sign_out_via = :delete + + # ==> OmniAuth + # Add a new OmniAuth provider. Check the wiki for more information on setting + # up on your models and hooks. + # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo' + + # ==> Warden configuration + # If you want to use other strategies, that are not supported by Devise, or + # change the failure app, you can configure them inside the config.warden block. + # + # config.warden do |manager| + # manager.intercept_401 = false + # manager.default_strategies(:scope => :user).unshift :some_external_strategy + # end +end diff --git a/spec/dummy/config/initializers/inflections.rb b/spec/dummy/config/initializers/inflections.rb new file mode 100644 index 0000000..9e8b013 --- /dev/null +++ b/spec/dummy/config/initializers/inflections.rb @@ -0,0 +1,10 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format +# (all these examples are active by default): +# ActiveSupport::Inflector.inflections do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end diff --git a/spec/dummy/config/initializers/mime_types.rb b/spec/dummy/config/initializers/mime_types.rb new file mode 100644 index 0000000..c0f11ba --- /dev/null +++ b/spec/dummy/config/initializers/mime_types.rb @@ -0,0 +1,6 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf +# Mime::Type.register_alias "text/html", :iphone +Mime::Type.register "application/svg+xml", :svg diff --git a/spec/dummy/config/initializers/secret_token.rb b/spec/dummy/config/initializers/secret_token.rb new file mode 100644 index 0000000..0820ce7 --- /dev/null +++ b/spec/dummy/config/initializers/secret_token.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +Dummy::Application.config.secret_token = 'df920e2a4c6d13b50ad08e5c4ecad0acc4c5925145b869a79113587c204b90059eeb79270bce426b9448733f2faa24772dddf68ee636ade6f444a66847407032' diff --git a/spec/dummy/config/initializers/session_store.rb b/spec/dummy/config/initializers/session_store.rb new file mode 100644 index 0000000..952473f --- /dev/null +++ b/spec/dummy/config/initializers/session_store.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +Dummy::Application.config.session_store :cookie_store, key: '_dummy_session' + +# Use the database for sessions instead of the cookie-based default, +# which shouldn't be used to store highly confidential information +# (create the session table with "rails generate session_migration") +# Dummy::Application.config.session_store :active_record_store diff --git a/spec/dummy/config/initializers/wrap_parameters.rb b/spec/dummy/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..999df20 --- /dev/null +++ b/spec/dummy/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] +end + +# Disable root element in JSON by default. +ActiveSupport.on_load(:active_record) do + self.include_root_in_json = false +end diff --git a/spec/dummy/config/locales/en.yml b/spec/dummy/config/locales/en.yml new file mode 100644 index 0000000..179c14c --- /dev/null +++ b/spec/dummy/config/locales/en.yml @@ -0,0 +1,5 @@ +# Sample localization file for English. Add more files in this directory for other locales. +# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. + +en: + hello: "Hello world" diff --git a/spec/dummy/config/routes.rb b/spec/dummy/config/routes.rb new file mode 100644 index 0000000..a28dcbd --- /dev/null +++ b/spec/dummy/config/routes.rb @@ -0,0 +1,60 @@ +Dummy::Application.routes.draw do + devise_for :users + + # The priority is based upon order of creation: + # first created -> highest priority. + + # Sample of regular route: + # match 'products/:id' => 'catalog#view' + # Keep in mind you can assign values other than :controller and :action + + # Sample of named route: + # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase + # This route can be invoked with purchase_url(:id => product.id) + + # Sample resource route (maps HTTP verbs to controller actions automatically): + # resources :products + + # Sample resource route with options: + # resources :products do + # member do + # get 'short' + # post 'toggle' + # end + # + # collection do + # get 'sold' + # end + # end + + # Sample resource route with sub-resources: + # resources :products do + # resources :comments, :sales + # resource :seller + # end + + # Sample resource route with more complex sub-resources + # resources :products do + # resources :comments + # resources :sales do + # get 'recent', :on => :collection + # end + # end + + # Sample resource route within a namespace: + # namespace :admin do + # # Directs /admin/products/* to Admin::ProductsController + # # (app/controllers/admin/products_controller.rb) + # resources :products + # end + + # You can have the root of your site routed with "root" + # just remember to delete public/index.html. + # root :to => 'welcome#index' + + # See how all your routes lay out with "rake routes" + + # This is a legacy wild controller route that's not recommended for RESTful applications. + # Note: This route will make all actions in every controller accessible via GET requests. + # match ':controller(/:action(/:id(.:format)))' +end diff --git a/spec/dummy/db/migrate/20111201121844_create_roles.rb b/spec/dummy/db/migrate/20111201121844_create_roles.rb new file mode 100644 index 0000000..30f8510 --- /dev/null +++ b/spec/dummy/db/migrate/20111201121844_create_roles.rb @@ -0,0 +1,12 @@ +class CreateRoles < ActiveRecord::Migration + def change + create_table :roles do |t| + t.string :name + t.text :display_name + t.text :note + t.integer :position + + t.timestamps + end + end +end diff --git a/spec/dummy/db/migrate/20111201155456_create_users.rb b/spec/dummy/db/migrate/20111201155456_create_users.rb new file mode 100644 index 0000000..72c4ef5 --- /dev/null +++ b/spec/dummy/db/migrate/20111201155456_create_users.rb @@ -0,0 +1,13 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.integer :user_group_id + t.integer :required_role_id + t.string :username + t.text :note + t.string :locale + + t.timestamps + end + end +end diff --git a/spec/dummy/db/migrate/20111201155513_add_devise_to_users.rb b/spec/dummy/db/migrate/20111201155513_add_devise_to_users.rb new file mode 100644 index 0000000..3379001 --- /dev/null +++ b/spec/dummy/db/migrate/20111201155513_add_devise_to_users.rb @@ -0,0 +1,31 @@ +class AddDeviseToUsers < ActiveRecord::Migration + def self.up + change_table(:users) do |t| + t.database_authenticatable :null => false + t.recoverable + t.rememberable + t.trackable + + # t.encryptable + # t.confirmable + # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both + # t.token_authenticatable + + + # Uncomment below if timestamps were not included in your original model. + # t.timestamps + end + + add_index :users, :email #, :unique => true + add_index :users, :reset_password_token, :unique => true + # add_index :users, :confirmation_token, :unique => true + # add_index :users, :unlock_token, :unique => true + # add_index :users, :authentication_token, :unique => true + end + + def self.down + # By default, we don't want to make any assumption about how to roll back a migration when your + # model already existed. Please edit below which fields you would like to remove in this migration. + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/spec/dummy/db/migrate/20111201163718_create_user_has_roles.rb b/spec/dummy/db/migrate/20111201163718_create_user_has_roles.rb new file mode 100644 index 0000000..701636e --- /dev/null +++ b/spec/dummy/db/migrate/20111201163718_create_user_has_roles.rb @@ -0,0 +1,10 @@ +class CreateUserHasRoles < ActiveRecord::Migration + def change + create_table :user_has_roles do |t| + t.integer :user_id + t.integer :role_id + + t.timestamps + end + end +end diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb new file mode 100644 index 0000000..bb6875c --- /dev/null +++ b/spec/dummy/db/schema.rb @@ -0,0 +1,62 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended to check this file into your version control system. + +ActiveRecord::Schema.define(:version => 20111201163718) do + + create_table "barcodes", :force => true do |t| + t.string "code_word" + t.binary "data" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "roles", :force => true do |t| + t.string "name" + t.text "display_name" + t.text "note" + t.integer "position" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "user_has_roles", :force => true do |t| + t.integer "user_id" + t.integer "role_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "users", :force => true do |t| + t.integer "user_group_id" + t.integer "required_role_id" + t.string "username" + t.text "note" + t.string "locale" + t.datetime "created_at" + t.datetime "updated_at" + t.string "email", :default => "", :null => false + t.string "encrypted_password", :limit => 128, :default => "", :null => false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", :default => 0 + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + end + + add_index "users", ["email"], :name => "index_users_on_email" + add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true + +end diff --git a/spec/dummy/lib/assets/.gitkeep b/spec/dummy/lib/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/log/.gitkeep b/spec/dummy/log/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/public/404.html b/spec/dummy/public/404.html new file mode 100644 index 0000000..9a48320 --- /dev/null +++ b/spec/dummy/public/404.html @@ -0,0 +1,26 @@ + + + + The page you were looking for doesn't exist (404) + + + + + +
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+ + diff --git a/spec/dummy/public/422.html b/spec/dummy/public/422.html new file mode 100644 index 0000000..83660ab --- /dev/null +++ b/spec/dummy/public/422.html @@ -0,0 +1,26 @@ + + + + The change you wanted was rejected (422) + + + + + +
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+ + diff --git a/spec/dummy/public/500.html b/spec/dummy/public/500.html new file mode 100644 index 0000000..b80307f --- /dev/null +++ b/spec/dummy/public/500.html @@ -0,0 +1,26 @@ + + + + We're sorry, but something went wrong (500) + + + + + +
+

We're sorry, but something went wrong.

+

We've been notified about this issue and we'll take a look at it shortly.

+
+ + diff --git a/spec/dummy/public/favicon.ico b/spec/dummy/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/script/rails b/spec/dummy/script/rails new file mode 100755 index 0000000..f8da2cf --- /dev/null +++ b/spec/dummy/script/rails @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby +# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. + +APP_PATH = File.expand_path('../../config/application', __FILE__) +require File.expand_path('../../config/boot', __FILE__) +require 'rails/commands' diff --git a/spec/factories/barcode.rb b/spec/factories/barcode.rb new file mode 100644 index 0000000..0f455ed --- /dev/null +++ b/spec/factories/barcode.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :barcode do |f| + f.code_word 'TEST' + end +end diff --git a/spec/factories/user.rb b/spec/factories/user.rb new file mode 100644 index 0000000..b72354b --- /dev/null +++ b/spec/factories/user.rb @@ -0,0 +1,31 @@ +FactoryGirl.define do + factory :admin, :class => User do |f| + f.sequence(:username){|n| "admin_#{n}"} + f.sequence(:email){|n| "admin_#{n}@example.jp"} + f.role {Role.find_by_name('Administrator')} + f.password 'adminpassword' + f.password_confirmation 'adminpassword' + f.required_role {Role.find_by_name('User')} + end + + factory :librarian, :class => User do |f| + f.sequence(:username){|n| "librarian_#{n}"} + f.sequence(:email){|n| "librarian_#{n}@example.jp"} + f.role {Role.find_by_name('Librarian')} + f.password 'librarianpassword' + f.password_confirmation 'librarianpassword' + f.required_role {Role.find_by_name('User')} + end + + factory :user, :class => User do |f| + f.sequence(:username){|n| "user_#{n}"} + f.sequence(:email){|n| "user_#{n}@example.jp"} + f.role {Role.find_by_name('User')} + f.password 'userpassword' + f.password_confirmation 'userpassword' + f.required_role {Role.find_by_name('User')} + end + + factory :invalid_user, :class => User do |f| + end +end diff --git a/spec/fixtures/roles.yml b/spec/fixtures/roles.yml new file mode 100644 index 0000000..23a52ab --- /dev/null +++ b/spec/fixtures/roles.yml @@ -0,0 +1,21 @@ +--- +role_00001: + name: Guest + display_name: Guest + id: 1 + note: +role_00002: + name: User + display_name: User + id: 2 + note: +role_00003: + name: Librarian + display_name: Librarian + id: 3 + note: +role_00004: + name: Administrator + display_name: Administrator + id: 4 + note: diff --git a/spec/fixtures/user_has_roles.yml b/spec/fixtures/user_has_roles.yml new file mode 100644 index 0000000..a25cdb6 --- /dev/null +++ b/spec/fixtures/user_has_roles.yml @@ -0,0 +1,41 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +admin: + user_id: 1 + role_id: 4 + +librarian1: + user_id: 2 + role_id: 3 + +user1: + user_id: 3 + role_id: 2 + +librarian2: + user_id: 4 + role_id: 3 + +user2: + user_id: 5 + role_id: 2 + +user3: + user_id: 6 + role_id: 2 + +user4: + user_id: 7 + role_id: 2 + +# == Schema Information +# +# Table name: user_has_roles +# +# id :integer not null, primary key +# user_id :integer +# role_id :integer +# created_at :datetime +# updated_at :datetime +# + diff --git a/spec/fixtures/users.yml b/spec/fixtures/users.yml new file mode 100644 index 0000000..06f18aa --- /dev/null +++ b/spec/fixtures/users.yml @@ -0,0 +1,69 @@ +--- +admin: + updated_at: 2008-05-31 13:16:30.163731 +09:00 + encrypted_password: $2a$10$vHohD1WflnTIqAa8zMkF9evwAgIZRw3XuR4d3bi29M.jph/MB/AJi + user_group_id: 2 + id: 1 + note: + username: admin + email: tanabe@kamata.lib.teu.ac.jp + created_at: 2007-11-19 16:58:32.111941 +09:00 + required_role_id: 4 +librarian1: + updated_at: 2008-05-31 12:41:16.337474 +09:00 + encrypted_password: $2a$10$9O2VuTccN4gHq36ARg0QReSrb1D7WrBBhZZ759RM9moHbB0W5zCzS + user_group_id: 1 + id: 2 + note: + username: librarian1 + email: librarian1@kamata.lib.teu.ac.jp + created_at: 2007-11-19 16:58:33.172441 +09:00 + required_role_id: 1 +user1: + updated_at: 2008-05-31 13:02:25.101261 +09:00 + encrypted_password: $2a$10$JthS59A0BNkDOoFpCXM0V.GhhffKaoWKbzpPahYp/vTFrOyM7h/uW + user_group_id: 1 + id: 3 + note: + username: user1 + email: user1@kamata.lib.teu.ac.jp + created_at: 2007-11-19 16:58:34.637413 +09:00 + required_role_id: 3 +librarian2: + updated_at: 2008-05-31 12:42:23.340575 +09:00 + encrypted_password: $2a$10$YmmTGrYQ1Ir6oc7wXnp.GuNeO1eYLoP3sv8wMSIrTdaGw2BPwRrpS + user_group_id: 1 + id: 4 + note: + username: librarian2 + created_at: 2008-01-18 12:24:04.222344 +09:00 + required_role_id: 1 +user2: + updated_at: 2008-05-31 12:42:44.711117 +09:00 + encrypted_password: $2a$10$i7UjJhLVrJM/J7qaTwW39OXw1NiwowUEbtNHVDV0sqMLjX9.UO9ca + user_group_id: 1 + id: 5 + note: + username: user2 + created_at: 2008-01-18 13:29:06.922728 +09:00 + required_role_id: 2 +user3: + updated_at: 2008-05-31 13:02:25.101261 +09:00 + encrypted_password: cc53de0c2d9a1a228daa9a673ec824473747e17507a6c3c4f7e5eff8821f531d4b9e23616b3ddc66fe17006b2298a556fbd567ac080e87f00f37eef8cee6c417 + user_group_id: 1 + id: 6 + note: + username: user3 + email: user3@kamata.lib.teu.ac.jp + created_at: 2007-11-19 16:58:34.637413 +09:00 + required_role_id: 3 +user4: + updated_at: 2008-05-31 13:02:25.101261 +09:00 + encrypted_password: cc53de0c2d9a1a228daa9a673ec824473747e17507a6c3c4f7e5eff8821f531d4b9e23616b3ddc66fe17006b2298a556fbd567ac080e87f00f37eef8cee6c417 + user_group_id: 1 + id: 7 + note: + username: user4 + email: user4@kamata.lib.teu.ac.jp + created_at: 2007-11-19 16:58:34.637413 +09:00 + required_role_id: 3 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..afbf65c --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,32 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV["RAILS_ENV"] ||= 'test' +require File.expand_path("../dummy/config/environment", __FILE__) +require 'rspec/rails' + +# Requires supporting ruby files with custom matchers and macros, etc, +# in spec/support/ and its subdirectories. +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } + +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 + + # 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.extend ControllerMacros, :type => :controller +end + +FactoryGirl.definition_file_paths << "#{::Rails.root}/../../spec/factories" +FactoryGirl.find_definitions diff --git a/spec/support/controller_macros.rb b/spec/support/controller_macros.rb new file mode 100644 index 0000000..4ebdba9 --- /dev/null +++ b/spec/support/controller_macros.rb @@ -0,0 +1,48 @@ +module ControllerMacros + def login_admin + before(:each) do + @request.env["devise.mapping"] = Devise.mappings[:admin] + sign_in Factory.create(:admin) + end + end + + def login_librarian + before(:each) do + @request.env["devise.mapping"] = Devise.mappings[:user] + user = Factory.create(:librarian) + sign_in user + end + end + + def login_user + before(:each) do + @request.env["devise.mapping"] = Devise.mappings[:user] + user = Factory.create(:user) + sign_in user + end + end + + def login_fixture_admin + before(:each) do + @request.env["devise.mapping"] = Devise.mappings[:admin] + @user = users(:admin) + sign_in @user + end + end + + def login_fixture_librarian + before(:each) do + @request.env["devise.mapping"] = Devise.mappings[:user] + @user = users(:librarian1) + sign_in @user + end + end + + def login_fixture_user + before(:each) do + @request.env["devise.mapping"] = Devise.mappings[:user] + @user = users(:user1) + sign_in @user + end + end +end diff --git a/spec/support/devise.rb b/spec/support/devise.rb new file mode 100644 index 0000000..5d898b4 --- /dev/null +++ b/spec/support/devise.rb @@ -0,0 +1,4 @@ +RSpec.configure do |config| + config.include Devise::TestHelpers, :type => :controller + config.include Devise::TestHelpers, :type => :view +end