Skip to content

Commit

Permalink
Fix engine issues and specs.
Browse files Browse the repository at this point in the history
- Fix assets so feature specs can run.
- Refactor test env
- Fix 3 of 4 failing specs (the one left id for regression test for
spree/spree#1687, probably something with rails4 sessions). The other
specs was fixed by bypassing gateway error on checkout.
- Refactor syntax for all specs —now they also readable :)
- Minor fixes to the engine, noticed issues with devise that needed to
be loaded before devise-encryptable.
- Bumped devise and cancan + all dev dependencies.
  • Loading branch information
futhr committed Mar 2, 2014
1 parent 2c88667 commit 3950a0e
Show file tree
Hide file tree
Showing 41 changed files with 593 additions and 570 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ spec/dummy
coverage
Gemfile.lock
*.swp
.rvmrc
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--color
5 changes: 0 additions & 5 deletions .simplecov

This file was deleted.

1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1.0
env:
- DB=sqlite
- DB=mysql
Expand Down
28 changes: 1 addition & 27 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
source 'https://rubygems.org'

gem 'json'
gem 'sqlite3'
gem 'mysql2'
gem 'pg'
gem 'multi_json'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 4.0.0'
gem 'coffee-rails', '~> 4.0.0'
end

group :test do
gem 'rspec-rails', '~> 2.13.0'
gem 'factory_girl_rails', '~> 4.2.1'
gem 'email_spec', '~> 1.4.0'

gem 'ffaker'
gem 'shoulda-matchers', '~> 1.4.2'
gem 'capybara', '~> 2.1'
gem 'database_cleaner', '~> 1.0.1'
gem 'selenium-webdriver', '2.35.1'
gem 'launchy'
end

gem 'spree', :github => "spree/spree", :branch => "master"
gem 'pry'
gem 'spree', github: 'spree/spree', branch: 'master'

gemspec
2 changes: 1 addition & 1 deletion LICENSE → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2007-2012, Spree Commerce, Inc. and other contributors
Copyright (c) 2014, Spree Commerce, Inc. and other contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ Provides authentication services for Spree, using the Devise gem.

At one stage in the past, this used to be the auth component for Spree. If that's the feature that you're now finding lacking from Spree, that's easy fixed.

Just add this line to your Gemfile:
Just add this line to your `Gemfile`:
```ruby
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master'
```

gem "spree_auth_devise", :github => "spree/spree_auth_devise"

Please ensure you're using the correct branch of spree_auth_devise relative to
your version of Spree.
Please ensure you're using the correct branch of `spree_auth_devise` relative to your version of Spree.

Spree 1.3.x or 1-3-stable:

gem 'spree_auth_devise', :github => "spree/spree_auth_devise", :branch => "1-3-stable"
```ruby
gem 'spree_auth_devise', :github => 'spree/spree_auth_devise', :branch => '1-3-stable'
```

Spree 1.2.x or 1-2-stable:

gem 'spree_auth_devise', :github => "spree/spree_auth_devise", :branch => "1-2-stable"
```ruby
gem 'spree_auth_devise', :github => 'spree/spree_auth_devise', :branch => '1-2-stable'
```

Then run `bundle install`. Authentication will then work exactly as it did in previous versions of Spree.

Expand All @@ -46,5 +48,4 @@ Then run the rspec tests.

bundle exec rake spec

If everything doesn't pass on your machine (using Ruby (1.9.3 or 2.0.0) and (MySQL or PostgreSQL or SQLite3)) then we would consider that a bug. Please file a bug report on the issues page for this project with your test output
and we will investigate it.
If everything doesn't pass on your machine (using Ruby (1.9.3 or 2.0.0) and (MySQL or PostgreSQL or SQLite3)) then we would consider that a bug. Please file a bug report on the issues page for this project with your test output and we will investigate it.
14 changes: 3 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
require 'rubygems'
require 'rake'
require 'rake/testtask'
require 'rake/packagetask'
require 'rubygems/package_task'
require 'bundler'
Bundler::GemHelper.install_tasks

require 'rspec/core/rake_task'
require 'spree/testing_support/common_rake'

RSpec::Core::RakeTask.new

task :default => :spec

spec = eval(File.read('spree_auth_devise.gemspec'))

Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end

desc 'Generates a dummy app for testing'
task :test_app do
ENV['LIB_NAME'] = 'spree/auth'
Expand Down
8 changes: 3 additions & 5 deletions Versionfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# This file is used to designate compatibilty with different versions of Spree
# Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details

"2.1.x" => { :branch => "master" }
"2.2.x" => { :branch => "2-2-stable" }
"2.1.x" => { :branch => "2-1-stable" }
"2.0.x" => { :branch => "2-0-stable" }
"1.3.x" => { :branch => "1-3-stable" }
"1.2.x" => { :branch => "1-2-stable" }
"1.2.x" => { :branch => "1-2-stable" }
2 changes: 1 addition & 1 deletion app/assets/javascripts/spree/backend/spree_auth.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// Placeholder for backend dummy application
//= require spree/backend
2 changes: 1 addition & 1 deletion app/assets/javascripts/spree/frontend/spree_auth.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// Placeholder for backend dummy application
//= require spree/frontend
4 changes: 3 additions & 1 deletion app/assets/stylesheets/spree/backend/spree_auth.css
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/* Placeholder for backend dummy app */
/*
*= require spree/backend
*/
4 changes: 3 additions & 1 deletion app/assets/stylesheets/spree/frontend/spree_auth.css
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/* Placeholder for backend dummy app */
/*
*= require spree/frontend
*/
2 changes: 1 addition & 1 deletion app/mailers/spree/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def reset_password_instructions(user, token, *args)
@edit_password_reset_url = spree.edit_spree_user_password_url(:reset_password_token => token)

mail(:to => user.email, :from => from_address,
:subject => Spree::Config[:site_name] + ' ' +
:subject => Spree::Config[:site_name] + ' ' +
I18n.t(:subject, :scope => [:devise, :mailer, :reset_password_instructions]))
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class User < ActiveRecord::Base
users_table_name = User.table_name
roles_table_name = Role.table_name

scope :admin, lambda { includes(:spree_roles).where("#{roles_table_name}.name" => "admin") }
scope :admin, -> { includes(:spree_roles).where("#{roles_table_name}.name" => "admin") }

class DestroyWithOrdersError < StandardError; end

Expand Down
10 changes: 5 additions & 5 deletions app/views/spree/user_mailer/reset_password_instructions.text.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
A request to reset your password has been made.
If you did not make this request, simply ignore this email.
A request to reset your password has been made.
If you did not make this request, simply ignore this email.

If you did make this request just click the link below:

<%= @edit_password_reset_url %>
If the above URL does not work try copying and pasting it into your browser.

If the above URL does not work try copying and pasting it into your browser.
If you continue to have problem please feel free to contact us.

1 change: 1 addition & 0 deletions lib/spree/auth/engine.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'devise'
require 'devise-encryptable'

module Spree
Expand Down
2 changes: 2 additions & 0 deletions lib/spree_auth_devise.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
require 'spree_core'
require 'spree/auth/devise'
require 'spree/authentication_helpers'
require 'coffee_script'
8 changes: 5 additions & 3 deletions script/rails
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/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.

ENGINE_PATH = File.expand_path('../..', __FILE__)
load File.expand_path('../../spec/dummy/script/rails', __FILE__)
ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/spree/auth/engine', __FILE__)

require 'rails/all'
require 'rails/engine/commands'
26 changes: 13 additions & 13 deletions spec/controllers/spree/admin/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,44 @@
user.spree_roles.clear
end

it 'should grant access to users with an admin role' do
it 'grant access to users with an admin role' do
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
spree_post :index
response.should render_template :index
expect(response).to render_template :index
end

it "allows admins to update a user's API key" do
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
mock_user.should_receive(:generate_spree_api_key!).and_return(true)
spree_put :generate_api_key, :id => mock_user.id
response.should redirect_to(spree.edit_admin_user_path(mock_user))
spree_put :generate_api_key, id: mock_user.id
expect(response).to redirect_to(spree.edit_admin_user_path(mock_user))
end

it "allows admins to clear a user's API key" do
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
mock_user.should_receive(:clear_spree_api_key!).and_return(true)
spree_put :clear_api_key, :id => mock_user.id
response.should redirect_to(spree.edit_admin_user_path(mock_user))
spree_put :clear_api_key, id: mock_user.id
expect(response).to redirect_to(spree.edit_admin_user_path(mock_user))
end

it 'should deny access to users with an bar role' do
it 'deny access to users with an bar role' do
user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
Spree::Ability.register_ability(BarAbility)
spree_post :index
response.should redirect_to('/unauthorized')
expect(response).to redirect_to '/unauthorized'
end

it 'should deny access to users with an bar role' do
it 'deny access to users with an bar role' do
user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
Spree::Ability.register_ability(BarAbility)
spree_post :update, { :id => '9' }
response.should redirect_to('/unauthorized')
spree_post :update, { id: '9' }
expect(response).to redirect_to '/unauthorized'
end

it 'should deny access to users without an admin role' do
it 'deny access to users without an admin role' do
user.stub :has_spree_role? => false
spree_post :index
response.should redirect_to('/unauthorized')
expect(response).to redirect_to '/unauthorized'
end
end
end
Loading

0 comments on commit 3950a0e

Please sign in to comment.