spree_redirects 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ .DS_Store
4
+ Gemfile.lock
5
+ pkg/*
6
+ lib/dummy_hooks/after_migrate.rb
7
+ test/dummy
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Redistribution and use in source and binary forms, with or without modification,
2
+ are permitted provided that the following conditions are met:
3
+
4
+ * Redistributions of source code must retain the above copyright notice,
5
+ this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice,
7
+ this list of conditions and the following disclaimer in the documentation
8
+ and/or other materials provided with the distribution.
9
+ * Neither the name of the Rails Dog LLC nor the names of its
10
+ contributors may be used to endorse or promote products derived from this
11
+ software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ Spree Redirects
2
+ ===============
3
+
4
+ Spree Redirects adds an interface for redirecting old urls to new ones. It's for when you replace an existing site with a shiny new spree site and want to avoid broken links and broken hearts.
5
+
6
+ To get a better idea of what it does, just follow the Demo instructions below...
7
+
8
+
9
+ Installation
10
+ ------------
11
+
12
+ Install spree_redirects by adding the following to your existing spree site's Gemfile:
13
+
14
+ gem 'spree_redirects', :git => 'git://github.com/citrus/spree_redirects.git'
15
+
16
+ Now bundle up:
17
+
18
+ bundle
19
+
20
+ Then run the generator which copies the migration template into your project:
21
+
22
+ rails g spree_redirects:install
23
+
24
+ Migrate your database:
25
+
26
+ rake db:migrate
27
+
28
+ And reboot your server:
29
+
30
+ rails s
31
+
32
+
33
+ You should be up and running now!
34
+
35
+
36
+ Testing
37
+ -------
38
+
39
+ Clone this repo to where you develop, bundle up and run dummier to get the show started:
40
+
41
+ git clone git://github.com/citrus/spree_redirects.git
42
+ cd spree_redirects
43
+ bundle install
44
+ bundle exec dummier
45
+
46
+ This will generate a fresh rails app in `test/dummy`, install spree_core & spree_redirects, then migrate the test database. Sweet.
47
+
48
+
49
+ ### If you'd like to use Spork
50
+
51
+ Boot the drb server with:
52
+
53
+ bundle exec spork
54
+
55
+ In another window, run all tests:
56
+
57
+ testdrb test/**/*_test.rb
58
+
59
+ Or just a specific test:
60
+
61
+ testdrb test/unit/redirect_test.rb
62
+
63
+
64
+ ### No Spork
65
+
66
+ If you don't want to spork, just use rake:
67
+
68
+ rake
69
+
70
+
71
+
72
+
73
+ Demo
74
+ ----
75
+
76
+ You can easily use the test/dummy app as a demo of spree_redirects. Just `cd` to where you develop and run:
77
+
78
+ git clone git://github.com/citrus/spree_redirects.git
79
+ cd spree_redirects
80
+ mv lib/dummy_hooks/after_migrate.rb.sample lib/dummy_hooks/after_migrate.rb
81
+ bundle install
82
+ bundle exec dummier
83
+ cd test/dummy
84
+ rails s
85
+
86
+
87
+ Contributors
88
+ ------------
89
+
90
+ So far it's just me; Spencer Steffen.
91
+
92
+ If you'd like to help out feel free to fork and send me pull requests!
93
+
94
+
95
+ License
96
+ -------
97
+
98
+ Copyright (c) 2011 Spencer Steffen and Citrus, released under the New BSD License All rights reserved.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must run `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rake/testtask'
11
+
12
+ Bundler::GemHelper.install_tasks
13
+
14
+ Rake::TestTask.new(:test) do |t|
15
+ t.libs << 'lib'
16
+ t.libs << 'test'
17
+ t.pattern = 'test/**/*_test.rb'
18
+ t.verbose = false
19
+ end
20
+
21
+ task :default => :test
@@ -0,0 +1,16 @@
1
+ class Admin::RedirectsController < Admin::ResourceController
2
+
3
+ def new
4
+ @redirect = Redirect.new
5
+ end
6
+
7
+ private
8
+
9
+ def collection
10
+ params[:search] ||= {}
11
+ params[:search][:meta_sort] ||= "old_url.asc"
12
+ @search = Redirect.search(params[:search])
13
+ @collection = @search.paginate(:per_page => Spree::Config[:orders_per_page], :page => params[:page])
14
+ end
15
+
16
+ end
@@ -0,0 +1,24 @@
1
+ class Redirect < ActiveRecord::Base
2
+
3
+ validates :old_url, :presence => true, :uniqueness => { :case_sensitive => false }
4
+ validates :new_url, :presence => true
5
+ validate :validate_urls
6
+
7
+ before_validation :normalize_urls
8
+
9
+ def normalize_urls
10
+ [ :old_url, :new_url ].map{|attribute| write_attribute attribute, normalize_url(send attribute) }
11
+ end
12
+
13
+ def validate_urls
14
+ errors.add(:base, I18n.t('duplicate_url_error')) if old_url == new_url
15
+ end
16
+
17
+ private
18
+
19
+ def normalize_url(url)
20
+ return url if url.blank?
21
+ url.to_s.downcase.sub!(/^[\/\s]*/, '/').strip
22
+ end
23
+
24
+ end
@@ -0,0 +1,11 @@
1
+ <%= form.field_container :old_url do %>
2
+ <%= form.label :old_url, t('old_url') %><br />
3
+ <%= form.text_field :old_url, :class => 'text' %>
4
+ <%= error_message_on :redirect, :old_url %>
5
+ <% end %>
6
+
7
+ <%= form.field_container :new_url do %>
8
+ <%= form.label :new_url, t('new_url') %><br />
9
+ <%= form.text_field :new_url, :class => 'text' %>
10
+ <%= error_message_on :redirect, :new_url %>
11
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <%= render 'shared/error_messages', :target => @redirect %>
4
+
5
+ <%= form_for([:admin, @redirect]) do |f| %>
6
+ <%= render "form", :form => f %>
7
+ <p class="form-buttons">
8
+ <%= button t("update") %> <%= t('or') %> <%= link_to t('cancel'), collection_url %>
9
+ </p>
10
+ <% end %>
@@ -0,0 +1,37 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <div class='toolbar'>
4
+ <ul class='actions'>
5
+ <li>
6
+ <p><%= button_link_to "New Redirect", new_object_url, :icon => 'add' %></p>
7
+ </li>
8
+ </ul>
9
+ <br class='clear' />
10
+ </div>
11
+
12
+
13
+ <h1>Listing Redirects</h1>
14
+
15
+ <table class="index">
16
+ <thead>
17
+ <tr>
18
+ <th><%= sort_link @search, :old_url, t('redirect.old_url') %></th>
19
+ <th><%= sort_link @search, :new_url, t('redirect.new_url') %></th>
20
+ <th><%= t('action') %></th>
21
+ </tr>
22
+ </thead>
23
+ <tbody>
24
+ <%- @collection.each do |redirect|%>
25
+ <tr id="<%= dom_id redirect %>">
26
+ <td><%= redirect.old_url %></td>
27
+ <td><%= redirect.new_url %></td>
28
+ <td>
29
+ <%= link_to_edit redirect %> &nbsp;
30
+ <%= link_to_delete redirect %>
31
+ </td>
32
+ </tr>
33
+ <% end %>
34
+ </tbody>
35
+ </table>
36
+
37
+ <%= will_paginate(:prev => "&#171; #{t('previous')}", :next => "#{t('next')} &#187;") %>
@@ -0,0 +1,13 @@
1
+ <%= render :partial => 'admin/shared/configuration_menu' %>
2
+
3
+ <h1><%= t '.new_redirect' %></h1>
4
+
5
+ <%= render 'shared/error_messages', :target => @redirect %>
6
+
7
+ <%= form_for([:admin, @redirect]) do |f| %>
8
+ <%= render "form", :form => f %>
9
+ <p class="form-buttons">
10
+ <%= button t('create') %> <%= t('or') %> <%= link_to t('cancel'), collection_url %>
11
+ </p>
12
+ <% end %>
13
+
@@ -0,0 +1,4 @@
1
+ <tr>
2
+ <td><%= link_to t("redirects"), admin_redirects_path %></td>
3
+ <td><%= t("explain_redirects") %></td>
4
+ </tr>
@@ -0,0 +1,7 @@
1
+ en:
2
+ old_url: Old URL
3
+ new_url: New URL
4
+ redirect: Redirect
5
+ redirects: Manage Redirects
6
+ explain_redirects: Forward old links to new ones
7
+ duplicate_url_error: The old URL may not be the same as the new URL.
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Rails.application.routes.draw do
2
+
3
+ namespace :admin do
4
+ resources :redirects
5
+ end
6
+
7
+ end
@@ -0,0 +1 @@
1
+ rake "db:migrate db:seed db:admin:create", :env => "development"
@@ -0,0 +1,2 @@
1
+ rake "spree_core:install" # spree_auth:install
2
+ run "rails g spree_redirects:install"
@@ -0,0 +1,30 @@
1
+ module SpreeRedirects
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+
5
+ include Rails::Generators::Migration
6
+
7
+ def self.count!
8
+ @count ||= 0
9
+ (@count += 1) * 3
10
+ end
11
+
12
+ def self.next_migration_number(path)
13
+ @time ||= Time.new.utc
14
+ if ActiveRecord::Base.timestamped_migrations
15
+ (@time + self.count!).strftime("%Y%m%d%H%M%S")
16
+ else
17
+ "%.3d" % (current_migration_number(dirname) + 1)
18
+ end
19
+ end
20
+
21
+ desc "Installs required migrations for spree_essentials"
22
+ source_root File.expand_path("../../templates", __FILE__)
23
+
24
+ def copy_migrations
25
+ migration_template "db/migrate/create_redirects.rb", "db/migrate/create_redirects.rb"
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,15 @@
1
+ class CreateRedirects < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :redirects do |t|
5
+ t.string :old_url
6
+ t.string :new_url
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :redirects
13
+ end
14
+
15
+ end
@@ -0,0 +1,17 @@
1
+ require 'spree_core'
2
+ require 'spree_redirects/custom_hooks'
3
+ require 'spree_redirects/redirect_middleware'
4
+
5
+ module SpreeRedirects
6
+
7
+ class Engine < Rails::Engine
8
+
9
+ config.autoload_paths += %W(#{config.root}/lib)
10
+
11
+ initializer "redirect middleware" do |app|
12
+ app.middleware.insert_before ::Rack::Lock, ::SpreeRedirects::RedirectMiddleware
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,7 @@
1
+ module SpreeRedirects
2
+ class CustomHooks < Spree::ThemeSupport::HookListener
3
+
4
+ insert_after :admin_configurations_menu, 'admin/shared/redirect_config'
5
+
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ module SpreeRedirects
2
+ class RedirectMiddleware
3
+
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ # execute the request using our Rails app
10
+ status, headers, body = @app.call(env)
11
+
12
+ if status == 404 && url = find_redirect([ env['PATH_INFO'], env['QUERY_STRING'] ].join("?").sub(/[\?\s]*$/, '').strip)
13
+ # Issue a "Moved permanently" response with the redirect location
14
+ [ 301, { "Location" => url }, 'Redirecting you to the new location...' ]
15
+ else
16
+ # Not a 404 or no redirect found, just send the response as is
17
+ [ status, headers, body ]
18
+ end
19
+ end
20
+
21
+ def find_redirect(url)
22
+ redirect = Redirect.find_by_old_url(url) rescue nil
23
+ return if redirect.nil?
24
+ redirect.new_url
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module SpreeRedirects
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "spree_redirects/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "spree_redirects"
7
+ s.version = SpreeRedirects::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Spencer Steffen"]
10
+ s.email = ["spencer@citrusme.com"]
11
+ s.homepage = "https://github.com/citrus/spree_redirects"
12
+ s.summary = %q{Spree Redirects adds an interface for redirecting old url's to new ones.}
13
+ s.description = %q{Spree Redirects adds an interface for redirecting old url's to new ones.}
14
+
15
+ s.rubyforge_project = "spree_redirects"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ # Spree
23
+ s.add_dependency('spree_core', '>= 0.60.0')
24
+
25
+ # Development
26
+ s.add_development_dependency('dummier', '>= 0.1.0')
27
+ s.add_development_dependency('shoulda', '>= 2.11.3')
28
+ s.add_development_dependency('spork', '>= 0.9.0.rc8')
29
+ s.add_development_dependency('spork-testunit', '>= 0.0.5')
30
+ s.add_development_dependency('factory_girl', '>= 2.0.0.beta2')
31
+ s.add_development_dependency('capybara', '>= 0.4.1')
32
+ s.add_development_dependency('sqlite3', '>= 1.3.3')
33
+
34
+ end
@@ -0,0 +1,77 @@
1
+ require_relative '../test_helper'
2
+
3
+ class AdminRedirectsTest < ActiveSupport::IntegrationCase
4
+
5
+ setup do
6
+ Redirect.destroy_all
7
+ @labels = %(Old URL, New URL).split(', ')
8
+ @values = %(booboo, woohoo).split(', ')
9
+ end
10
+
11
+ should "have a link to redirects from config page" do
12
+ visit admin_configurations_path
13
+ assert has_link?("Manage Redirects")
14
+ end
15
+
16
+ should "have a link to new redirect" do
17
+ visit admin_redirects_path
18
+ btn = find(".actions a.button").native
19
+ assert_match /#{new_admin_redirect_path}$/, btn.attribute('href')
20
+ assert_equal "New Redirect", btn.text
21
+ end
22
+
23
+ should "get new redirect" do
24
+ visit new_admin_redirect_path
25
+ assert has_content?("New Redirect")
26
+ within "#new_redirect" do
27
+ @labels.each do |f|
28
+ assert has_field?(f)
29
+ end
30
+ end
31
+ end
32
+
33
+ should "validate redirect" do
34
+ visit new_admin_redirect_path
35
+ click_button "Create"
36
+ within "#errorExplanation" do
37
+ assert_seen "3 errors prohibited this record from being saved:"
38
+ assert_seen "Old url can't be blank"
39
+ assert_seen "New url can't be blank"
40
+ assert_seen "The old URL may not be the same as the new URL."
41
+ end
42
+ end
43
+
44
+ should "create a redirect" do
45
+ visit new_admin_redirect_path
46
+ within "#new_redirect" do
47
+ @labels.each_with_index do |label, index|
48
+ fill_in label, :with => @values[index]
49
+ end
50
+ end
51
+ click_button "Create"
52
+ assert_flash(:notice, "Redirect has been successfully created!")
53
+ end
54
+
55
+ context "an existing redirect" do
56
+ setup do
57
+ @redirect = Redirect.create(:old_url => "booboo", :new_url => "woohoo")
58
+ end
59
+
60
+ should "update redirect, user and addresses" do
61
+ visit edit_admin_redirect_path(@redirect)
62
+
63
+ within "#edit_redirect_#{@redirect.id}" do
64
+ @labels.each_with_index do |label, index|
65
+ fill_in label, :with => @values[index].reverse
66
+ end
67
+ end
68
+ click_button "Update"
69
+ assert_equal admin_redirects_path, current_path
70
+ assert_flash(:notice, "Redirect has been successfully updated!")
71
+ assert_seen "/ooboob", :within => "tr#redirect_#{@redirect.id} td:first-child"
72
+ assert_seen "/oohoow", :within => "tr#redirect_#{@redirect.id} td:nth-child(2)"
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../test_helper'
2
+
3
+ class AdminRedirectsTest < ActiveSupport::IntegrationCase
4
+
5
+ def setup
6
+ Redirect.destroy_all
7
+ @redirect = Redirect.create(:old_url => "shop-online.html", :new_url => "products")
8
+ end
9
+
10
+ should "redirect with simple url" do
11
+ visit @redirect.old_url
12
+ assert_equal current_path, @redirect.new_url
13
+ end
14
+
15
+ should "redirect with a query string" do
16
+ assert @redirect.update_attributes(:old_url => "shop?online=true&something=nothing")
17
+ visit @redirect.old_url
18
+ assert_equal current_path, @redirect.new_url
19
+ end
20
+
21
+ end
@@ -0,0 +1,22 @@
1
+ begin
2
+
3
+ FactoryGirl.define do
4
+
5
+ factory :user do
6
+ email { random_email }
7
+ password "spree123"
8
+ password_confirmation "spree123"
9
+ roles { [Role.find_or_create_by_name("user")] }
10
+ end
11
+
12
+ factory :admin_user, :parent => :user do
13
+ roles { [Role.find_or_create_by_name("admin")] }
14
+ end
15
+
16
+ end
17
+
18
+ rescue FactoryGirl::DuplicateDefinitionError
19
+
20
+ puts "factories are already defined..."
21
+
22
+ end
@@ -0,0 +1,11 @@
1
+ module HelperMethods
2
+
3
+ def random_email
4
+ random_token.split("").insert(random_token.length / 2, "@").push(".com").join("")
5
+ end
6
+
7
+ def random_token
8
+ Digest::SHA1.hexdigest((Time.now.to_i * rand).to_s)
9
+ end
10
+
11
+ end
@@ -0,0 +1,26 @@
1
+ # Define a bare test case to use with Capybara
2
+
3
+ class ActiveSupport::IntegrationCase < ActiveSupport::TestCase
4
+
5
+ include Capybara
6
+ include Rails.application.routes.url_helpers
7
+
8
+ self.use_transactional_fixtures = false
9
+
10
+ def assert_seen(text, opts={})
11
+ if opts[:within]
12
+ within(opts[:within]) do
13
+ assert has_content?(text)
14
+ end
15
+ else
16
+ assert has_content?(text)
17
+ end
18
+ end
19
+
20
+ def assert_flash(key, text)
21
+ within(".flash.#{key}") do
22
+ assert_seen(text)
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,33 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+ require 'spork'
4
+
5
+ Spork.prefork do
6
+
7
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
8
+ require "rails/test_help"
9
+ require "shoulda"
10
+ require "factory_girl"
11
+ require "sqlite3"
12
+
13
+ require "capybara/rails"
14
+ require "selenium/webdriver"
15
+
16
+ Rails.backtrace_cleaner.remove_silencers!
17
+
18
+ Capybara.default_driver = :selenium
19
+ Capybara.default_selector = :css
20
+
21
+ # Run any available migration if needed
22
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
23
+
24
+ end
25
+
26
+ Spork.each_run do
27
+
28
+ # Load support files
29
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| load f }
30
+
31
+ include HelperMethods
32
+
33
+ end
@@ -0,0 +1,66 @@
1
+ require_relative '../test_helper'
2
+
3
+ class RedirectTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ Redirect.destroy_all
7
+ @redirect = Redirect.new
8
+ end
9
+
10
+ should "require urls to be set" do
11
+ assert !@redirect.valid?
12
+ assert !@redirect.save
13
+ assert @redirect.errors.include?(:old_url)
14
+ assert @redirect.errors.include?(:new_url)
15
+ end
16
+
17
+ should "not allow old to equal new" do
18
+ @redirect.old_url = @redirect.new_url = "omgomg"
19
+ assert !@redirect.valid?
20
+ assert !@redirect.save
21
+ assert @redirect.errors.include?(:base)
22
+ end
23
+
24
+ should "strip extra spaces" do
25
+ @redirect.attributes = { :old_url => " booboo ", :new_url => " woohoo " }
26
+ assert @redirect.save
27
+ assert_equal @redirect.old_url, "/booboo"
28
+ assert_equal @redirect.new_url, "/woohoo"
29
+ end
30
+
31
+ should "not duplicate starting slash" do
32
+ @redirect.attributes = { :old_url => "/booboo", :new_url => "/woohoo" }
33
+ assert @redirect.save
34
+ assert_equal @redirect.old_url, "/booboo"
35
+ assert_equal @redirect.new_url, "/woohoo"
36
+ end
37
+
38
+ should "remove multiple slashes" do
39
+ @redirect.attributes = { :old_url => "//booboo", :new_url => "////////woohoo" }
40
+ assert @redirect.save
41
+ assert_equal @redirect.old_url, "/booboo"
42
+ assert_equal @redirect.new_url, "/woohoo"
43
+ end
44
+
45
+ should "remove multiple slashes with spaces between" do
46
+ @redirect.attributes = { :old_url => "/ /booboo", :new_url => "// / / //woohoo" }
47
+ assert @redirect.save
48
+ assert_equal @redirect.old_url, "/booboo"
49
+ assert_equal @redirect.new_url, "/woohoo"
50
+ end
51
+
52
+ context "a url with proper attributes" do
53
+
54
+ setup do
55
+ @redirect.attributes = { :old_url => "booboo", :new_url => "woohoo" }
56
+ end
57
+
58
+ should "ensure starting slash" do
59
+ assert @redirect.save
60
+ assert_equal @redirect.old_url, "/booboo"
61
+ assert_equal @redirect.new_url, "/woohoo"
62
+ end
63
+
64
+ end
65
+
66
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_redirects
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Spencer Steffen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-02 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: spree_core
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.60.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: dummier
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.1.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: shoulda
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.11.3
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: spork
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 0.9.0.rc8
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: spork-testunit
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 0.0.5
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: factory_girl
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.0.0.beta2
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: capybara
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.4.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: sqlite3
95
+ requirement: &id008 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 1.3.3
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *id008
104
+ description: Spree Redirects adds an interface for redirecting old url's to new ones.
105
+ email:
106
+ - spencer@citrusme.com
107
+ executables: []
108
+
109
+ extensions: []
110
+
111
+ extra_rdoc_files: []
112
+
113
+ files:
114
+ - .gitignore
115
+ - Gemfile
116
+ - LICENSE
117
+ - README.md
118
+ - Rakefile
119
+ - app/controllers/admin/redirects_controller.rb
120
+ - app/models/redirect.rb
121
+ - app/views/admin/redirects/_form.html.erb
122
+ - app/views/admin/redirects/edit.html.erb
123
+ - app/views/admin/redirects/index.html.erb
124
+ - app/views/admin/redirects/new.html.erb
125
+ - app/views/admin/shared/_redirect_config.html.erb
126
+ - config/locales/en.yml
127
+ - config/routes.rb
128
+ - lib/dummy_hooks/after_migrate.rb.sample
129
+ - lib/dummy_hooks/before_migrate.rb
130
+ - lib/generators/spree_redirects/install_generator.rb
131
+ - lib/generators/templates/db/migrate/create_redirects.rb
132
+ - lib/spree_redirects.rb
133
+ - lib/spree_redirects/custom_hooks.rb
134
+ - lib/spree_redirects/redirect_middleware.rb
135
+ - lib/spree_redirects/version.rb
136
+ - spree_redirects.gemspec
137
+ - test/integration/admin_redirects_test.rb
138
+ - test/integration/redirect_middleware_test.rb
139
+ - test/support/fixtures.rb
140
+ - test/support/helper_methods.rb
141
+ - test/support/integration_case.rb
142
+ - test/test_helper.rb
143
+ - test/unit/redirect_test.rb
144
+ has_rdoc: true
145
+ homepage: https://github.com/citrus/spree_redirects
146
+ licenses: []
147
+
148
+ post_install_message:
149
+ rdoc_options: []
150
+
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ hash: 923679590247154286
159
+ segments:
160
+ - 0
161
+ version: "0"
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ none: false
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ hash: 923679590247154286
168
+ segments:
169
+ - 0
170
+ version: "0"
171
+ requirements: []
172
+
173
+ rubyforge_project: spree_redirects
174
+ rubygems_version: 1.6.2
175
+ signing_key:
176
+ specification_version: 3
177
+ summary: Spree Redirects adds an interface for redirecting old url's to new ones.
178
+ test_files:
179
+ - test/integration/admin_redirects_test.rb
180
+ - test/integration/redirect_middleware_test.rb
181
+ - test/support/fixtures.rb
182
+ - test/support/helper_methods.rb
183
+ - test/support/integration_case.rb
184
+ - test/test_helper.rb
185
+ - test/unit/redirect_test.rb