exstatic 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/.gitignore +20 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +8 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +36 -0
  6. data/Rakefile +27 -0
  7. data/app/controllers/exstatic/pages_controller.rb +37 -0
  8. data/app/models/exstatic/page.rb +9 -0
  9. data/app/views/exstatic/pages/display.html.erb +1 -0
  10. data/app/views/exstatic/pages/index.html.erb +8 -0
  11. data/app/views/exstatic/pages/new.html.erb +33 -0
  12. data/app/views/exstatic/pages/show.html.erb +6 -0
  13. data/config/routes.rb +4 -0
  14. data/exstatic.gemspec +24 -0
  15. data/lib/exstatic/engine.rb +23 -0
  16. data/lib/exstatic/validators/nonexistant_path_validator.rb +20 -0
  17. data/lib/exstatic/version.rb +3 -0
  18. data/lib/exstatic.rb +11 -0
  19. data/lib/generators/exstatic/install_generator.rb +15 -0
  20. data/lib/generators/exstatic/templates/migration.rb +11 -0
  21. data/spec/controllers/pages_controller_spec.rb +133 -0
  22. data/spec/exstatic_spec.rb +8 -0
  23. data/spec/lib/exstatic/engine_spec.rb +37 -0
  24. data/spec/lib/validators/nonexistant_path_validator_spec.rb +38 -0
  25. data/spec/models/page_spec.rb +25 -0
  26. data/spec/rails_app/Rakefile +7 -0
  27. data/spec/rails_app/app/assets/images/rails.png +0 -0
  28. data/spec/rails_app/app/assets/javascripts/application.js +13 -0
  29. data/spec/rails_app/app/assets/stylesheets/application.css +13 -0
  30. data/spec/rails_app/app/controllers/application_controller.rb +3 -0
  31. data/spec/rails_app/app/controllers/home_controller.rb +5 -0
  32. data/spec/rails_app/app/helpers/application_helper.rb +2 -0
  33. data/spec/rails_app/app/mailers/.gitkeep +0 -0
  34. data/spec/rails_app/app/models/.gitkeep +0 -0
  35. data/spec/rails_app/app/views/home/custom_route.html.erb +1 -0
  36. data/spec/rails_app/app/views/layouts/application.html.erb +14 -0
  37. data/spec/rails_app/config/application.rb +60 -0
  38. data/spec/rails_app/config/boot.rb +10 -0
  39. data/spec/rails_app/config/database.yml +25 -0
  40. data/spec/rails_app/config/environment.rb +5 -0
  41. data/spec/rails_app/config/environments/development.rb +37 -0
  42. data/spec/rails_app/config/environments/production.rb +67 -0
  43. data/spec/rails_app/config/environments/test.rb +37 -0
  44. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  45. data/spec/rails_app/config/initializers/exstatic.rb +1 -0
  46. data/spec/rails_app/config/initializers/inflections.rb +15 -0
  47. data/spec/rails_app/config/initializers/mime_types.rb +5 -0
  48. data/spec/rails_app/config/initializers/secret_token.rb +7 -0
  49. data/spec/rails_app/config/initializers/session_store.rb +8 -0
  50. data/spec/rails_app/config/initializers/wrap_parameters.rb +14 -0
  51. data/spec/rails_app/config/locales/en.yml +5 -0
  52. data/spec/rails_app/config/routes.rb +10 -0
  53. data/spec/rails_app/config.ru +4 -0
  54. data/spec/rails_app/db/development.sqlite3 +0 -0
  55. data/spec/rails_app/db/migrate/20130131035818_exstatic_create_exstatic_pages.rb +11 -0
  56. data/spec/rails_app/db/schema.rb +24 -0
  57. data/spec/rails_app/db/seeds.rb +7 -0
  58. data/spec/rails_app/db/test.sqlite3 +0 -0
  59. data/spec/rails_app/lib/assets/.gitkeep +0 -0
  60. data/spec/rails_app/lib/tasks/.gitkeep +0 -0
  61. data/spec/rails_app/log/.gitkeep +0 -0
  62. data/spec/rails_app/public/404.html +26 -0
  63. data/spec/rails_app/public/422.html +26 -0
  64. data/spec/rails_app/public/500.html +25 -0
  65. data/spec/rails_app/public/favicon.ico +0 -0
  66. data/spec/rails_app/public/index.html +241 -0
  67. data/spec/rails_app/public/robots.txt +5 -0
  68. data/spec/rails_app/script/rails +6 -0
  69. data/spec/spec_helper.rb +17 -0
  70. metadata +227 -0
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ *.log
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ coverage/*
20
+ /bin/
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ruby-1.9.3-p374@exstatic --create
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in static_charge.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem "sqlite3"
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Josh Schramm
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Exstatic
2
+
3
+ Exstatic is an embedded content management system for Ruby on
4
+ Rails. It integrates with a Rails 3.1+ web application to allow managed
5
+ content creation for "static" pages.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'exstatic'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install exstatic
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Gem Todos
26
+
27
+ TODO: Create a test runner rake task that resets test db in dummy app
28
+ TODO: Figure out how to support Mongoid
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Exstatic'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/rails_app/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,37 @@
1
+ class Exstatic::PagesController < ApplicationController
2
+ before_filter Exstatic.authorization_method, :only => Exstatic.authorization_actions
3
+
4
+ def index
5
+ @pages = Exstatic::Page.all
6
+ end
7
+
8
+ def show
9
+ @page = Exstatic::Page.find(params[:id])
10
+ end
11
+
12
+ def new
13
+ @page = Exstatic::Page.new
14
+ end
15
+
16
+ def display
17
+ @page = Exstatic::Page.where(:slug => stripped_path).first!
18
+ end
19
+
20
+ def create
21
+ @page = Exstatic::Page.new(params[:page])
22
+ if @page.save
23
+ redirect_to @page
24
+ else
25
+ render :new
26
+ end
27
+ end
28
+
29
+ private
30
+ def authorize_exstatic_pages
31
+ super if defined?(super)
32
+ end
33
+
34
+ def stripped_path
35
+ request.fullpath.gsub(/^\//, "")
36
+ end
37
+ end
@@ -0,0 +1,9 @@
1
+ include Exstatic::Validators
2
+
3
+ module Exstatic
4
+ class Page < ActiveRecord::Base
5
+ validates :slug, :nonexistant_path => true, :uniqueness => true
6
+
7
+ attr_accessible :title, :content, :slug
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ <p><%= @page.content %></p>
@@ -0,0 +1,8 @@
1
+ <h1> This will be a listing of pages</h1>
2
+ <ul>
3
+ <% @pages.each do |p| %>
4
+ <li><%= link_to p.title, p %>
5
+ <% end %>
6
+ </ul>
7
+
8
+ <%= link_to "New Page", new_page_path %>
@@ -0,0 +1,33 @@
1
+ <div id="errors_container" class="<%= @page.errors.count > 0 ? "" : "hidden" %> <%= @page.class.name.downcase %>_errors">
2
+ <h2>
3
+ <% if defined? heading %>
4
+ <%= t(heading) %>
5
+ <% else %>
6
+ <%= t(:save_error) %>
7
+ <% end %>
8
+ </h2>
9
+ <ul id="errors">
10
+ <% @page.errors.full_messages.each do |msg| %>
11
+ <li><%= msg %></li>
12
+ <% end %>
13
+ </ul>
14
+ </div>
15
+
16
+ <h1>Create a Page</h1>
17
+ <%= form_for @page do |f| %>
18
+ <div>
19
+ <%= f.label :title %>
20
+ <%= f.text_field :title %>
21
+ </div>
22
+ <div>
23
+ <%= f.label :slug %>
24
+ <%= f.text_field :slug %>
25
+ </div>
26
+ <div>
27
+ <%= f.label :content %>
28
+ <%= f.text_field :content %>
29
+ </div>
30
+ <div>
31
+ <%= f.submit %>
32
+ </div>
33
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1><%= @page.title %></h1>
2
+ <p><%= @page.content %></p>
3
+
4
+ <strong>Slug: </strong><%= @page.slug %><br>
5
+
6
+ <%= link_to "Back to list", pages_path %>
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ Exstatic::Engine.routes.draw do
2
+ resources :pages, :controller => "pages", :path => "/pages"
3
+ root :to => "exstatic/pages#index"
4
+ end
data/exstatic.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ require 'exstatic/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "exstatic"
7
+ gem.version = Exstatic::VERSION
8
+ gem.authors = ["Josh Schramm"]
9
+ gem.email = ["josh.schramm@gmail.com"]
10
+ gem.description = %q{Allows managed content pages in a Ruby on Rails 3.1+ application.}
11
+ gem.summary = %q{Allows managed content pages in a Ruby on Rails 3.1+ application.}
12
+ gem.homepage = "http://github.com/JoshReedSchramm/exstatic"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_dependency "rails", "~> 3.2.11"
20
+
21
+ gem.add_development_dependency("rspec", "~> 2.12.0")
22
+ gem.add_development_dependency("rspec-rails", "~> 2.12.0")
23
+ gem.add_development_dependency "tzinfo"
24
+ end
@@ -0,0 +1,23 @@
1
+ module Exstatic
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Exstatic
4
+
5
+ config.exstatic = Exstatic
6
+
7
+ initializer 'exstatic.bind_dynamic_routes', :after => :disable_dependency_loading do |app|
8
+ begin
9
+ app.routes.disable_clear_and_finalize = true
10
+ app.routes.draw do
11
+ Exstatic::Page.all.each do |p|
12
+ get "/#{p.slug}", :to => "exstatic/pages#display"
13
+ end
14
+ end
15
+ rescue
16
+ Rails.logger.error "Failed to bind custom page routes for Exstatic"
17
+ ensure
18
+ app.routes.disable_clear_and_finalize = false
19
+ app.routes.finalize!
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ module Exstatic
2
+ module Validators
3
+ class NonexistantPathValidator < ActiveModel::EachValidator
4
+ def validate_each(object, attribute, value)
5
+ return true if value.blank?
6
+
7
+ path = '/' + value
8
+
9
+ begin
10
+ route = Rails.application.routes.recognize_path(path, :method => :get)
11
+
12
+ if route && !route[:controller].starts_with?("exstatic/")
13
+ object.errors[attribute] << (options[:message] || "matches an existing path")
14
+ end
15
+ rescue ActionController::RoutingError
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Exstatic
2
+ VERSION = "0.0.1"
3
+ end
data/lib/exstatic.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'exstatic/engine'
2
+ require 'exstatic/validators/nonexistant_path_validator'
3
+
4
+ module Exstatic
5
+
6
+ mattr_accessor :authorization_method
7
+ @@authorization_method = :authorize_exstatic_pages
8
+
9
+ mattr_accessor :authorization_actions
10
+ @@authorization_actions = [:new, :create, :edit, :update, :destroy, :index, :show]
11
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module Exstatic
4
+ module Generators
5
+ class InstallGenerator < ActiveRecord::Generators::Base
6
+ desc "Copies migrations and initialization components into your application"
7
+
8
+ source_root File.expand_path("../templates", __FILE__)
9
+
10
+ def copy_migration
11
+ migration_template "migration.rb", "db/migrate/exstatic_create_exstatic_pages"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ class ExstaticCreateExstaticPages < ActiveRecord::Migration
2
+ def change
3
+ create_table(:exstatic_pages) do |t|
4
+ t.string :title
5
+ t.text :content
6
+ t.string :slug
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+
3
+ describe Exstatic::PagesController do
4
+ describe "GET index" do
5
+ it 'can render the listing page' do
6
+ pages = [mock]
7
+ Exstatic::Page.stub(:all).and_return(pages)
8
+ get :index, { :use_route => :exstatic }
9
+
10
+ response.should be_success
11
+ response.should render_template('index')
12
+ assigns(:pages).should == pages
13
+ end
14
+ end
15
+
16
+
17
+ it 'can serve a form to create a new page' do
18
+ # fake a login
19
+ get :new, { :use_route => :exstatic }
20
+
21
+ response.should render_template('new')
22
+ end
23
+
24
+ describe 'POST create' do
25
+ context 'and the page is valid' do
26
+ it 'redirects to the page details' do
27
+ page = mock_model(Exstatic::Page)
28
+
29
+ Exstatic::Page.stub(:new).and_return(page)
30
+ page.should_receive(:save).and_return(true)
31
+
32
+ post :create, {:page => { :title => "foo" }, :use_route => :exstatic }
33
+
34
+ response.should redirect_to page_path(page)
35
+ end
36
+ end
37
+
38
+ context 'and the page is invalid' do
39
+ it 'rerenders the form' do
40
+ page = mock(Exstatic::Page)
41
+
42
+ Exstatic::Page.stub(:new).and_return(page)
43
+ page.should_receive(:save).and_return(false)
44
+
45
+ post :create, {:page => { :title => "foo" }, :use_route => :exstatic }
46
+
47
+ response.should render_template(:new)
48
+ end
49
+ end
50
+ end
51
+
52
+ describe "GET show" do
53
+ it "renders the page" do
54
+ page = mock_model(Exstatic::Page)
55
+ Exstatic::Page.stub(:find).and_return(page)
56
+
57
+ get :show, {:id => 1, :use_route => :exstatic}
58
+
59
+ response.should render_template(:show)
60
+ assigns(:page).should == page
61
+ end
62
+ end
63
+
64
+ describe "GET display" do
65
+ it "renders the page based on the request path" do
66
+ page = mock_model(Exstatic::Page)
67
+
68
+ request.stub(:fullpath).and_return("/the/page/path")
69
+ Exstatic::Page.stub(:where).with(:slug => "the/page/path").and_return(page)
70
+ page.stub(:first!).and_return(page)
71
+
72
+ get :display, { :use_route => :exstatic }
73
+
74
+ response.should be_success
75
+ response.should render_template(:display)
76
+
77
+ assigns(:page).should == page
78
+ end
79
+ end
80
+
81
+ context "When authorizing the user to make changes to a page" do
82
+ describe "when the default method is defined in application controller" do
83
+ before(:each) do
84
+ class ApplicationController
85
+ private
86
+ def authorize_exstatic_pages
87
+ render :status => 402 and return
88
+ end
89
+ end
90
+ end
91
+ it "returns a 402 auth failure" do
92
+ get :new, { :use_route => :exstatic }
93
+ response.status.should == 402
94
+ end
95
+ end
96
+
97
+ describe "when a custom method has been defined" do
98
+ before(:each) do
99
+ Exstatic.authorization_method = :custom_page_auth
100
+ class ApplicationController
101
+ private
102
+ def custom_page_auth
103
+ render :status => 402 and return
104
+ end
105
+ end
106
+ end
107
+ it "returns a 402 auth failure" do
108
+ get :new, { :use_route => :exstatic }
109
+ response.status.should == 402
110
+ end
111
+ end
112
+
113
+ describe "when secure methods have been overridden" do
114
+ before(:each) do
115
+ class ApplicationController
116
+ private
117
+ def authorize_exstatic_pages
118
+ render :status => 402 and return
119
+ end
120
+ end
121
+ end
122
+ it "allows access to the non-filtered method" do
123
+ get :index, { :use_route => :exstatic }
124
+ response.status.should == 200
125
+ end
126
+
127
+ it "returns a 402 auth failure for filtered methods" do
128
+ get :new, { :use_route => :exstatic }
129
+ response.status.should == 402
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe "When testing exstatic" do
4
+ it "includes a dummy rails application" do
5
+ RailsApp.should be_a(Module)
6
+ Exstatic.should be_a(Module)
7
+ end
8
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Exstatic::Engine do
4
+ it "dynamically adds routes from pages at initialization" do
5
+ Exstatic::Page.create(:slug => "rspec/test", :title => "Rspec Test", :content => "This is an rspec test")
6
+
7
+ initializer = Exstatic::Engine.initializers.select { |i| i.name == "exstatic.bind_dynamic_routes" }.first
8
+ initializer.run(Rails.application)
9
+
10
+ route = Rails.application.routes.recognize_path("/rspec/test", :method => :get)
11
+ route.should_not be_nil
12
+ end
13
+
14
+ it "does preserves existing routes" do
15
+ initializer = Exstatic::Engine.initializers.select { |i| i.name == "exstatic.bind_dynamic_routes" }.first
16
+ initializer.run(Rails.application)
17
+
18
+ route = Rails.application.routes.recognize_path("/custompage", :method => :get)
19
+ route.should_not be_nil
20
+ route[:controller].should == "home"
21
+ end
22
+
23
+ it "does not override pre-existing routes" do
24
+ p = Exstatic::Page.new(:slug => "custompage", :title => "Rspec Test", :content => "This is an rspec test")
25
+ p.save(:validate => false)
26
+
27
+ verify_saved = Exstatic::Page.where(:slug => "custompage").first!
28
+ verify_saved.should_not be_nil
29
+
30
+ initializer = Exstatic::Engine.initializers.select { |i| i.name == "exstatic.bind_dynamic_routes" }.first
31
+ initializer.run(Rails.application)
32
+
33
+ route = Rails.application.routes.recognize_path("/custompage", :method => :get)
34
+ route.should_not be_nil
35
+ route[:controller].should == "home"
36
+ end
37
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Exstatic::Validators::NonexistantPathValidator do
4
+ context "when a path exists matching the one provided" do
5
+ it "fails" do
6
+ page = Exstatic::Page.new(:slug => "custompage")
7
+
8
+ validator = Exstatic::Validators::NonexistantPathValidator.new({:attributes => {}})
9
+ validator.validate_each(page, :slug, page.slug)
10
+
11
+ page.errors[:slug].first.should == "matches an existing path"
12
+ end
13
+ end
14
+
15
+ context "when no path exists matching the one provided" do
16
+ it "succeeds" do
17
+ page = Exstatic::Page.new(:slug => "brandnewpage")
18
+
19
+ validator = Exstatic::Validators::NonexistantPathValidator.new({:attributes => {}})
20
+ validator.validate_each(page, :slug, page.slug)
21
+
22
+ page.errors[:slug].empty?.should == true
23
+
24
+ end
25
+ end
26
+
27
+ context "when a matchinj path is from exstatic" do
28
+ it "succeeds" do
29
+ page = Exstatic::Page.new(:slug => "foo/bar")
30
+
31
+ validator = Exstatic::Validators::NonexistantPathValidator.new({:attributes => {}})
32
+ validator.validate_each(page, :slug, page.slug)
33
+
34
+ page.errors[:slug].empty?.should == true
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Exstatic::Page do
4
+ it "can be saved" do
5
+ page = Exstatic::Page.new(:title => "This is my page", :slug => "foo", :content => "This is some content")
6
+ page.save.should be_true
7
+
8
+ page2 = Exstatic::Page.where(:slug => "foo").first!
9
+ page2.should == page
10
+ end
11
+
12
+ it "validates that another routes with the same path does not exist" do
13
+ page = Exstatic::Page.new(:title => "foo", :content => "bar", :slug => "custompage")
14
+ page.save.should be_false
15
+ page.errors[:slug].should_not be_nil
16
+ end
17
+
18
+ it "validates that the slug is unique" do
19
+ page1 = Exstatic::Page.create(:title => "This is my page", :slug => "foo", :content => "This is some content")
20
+
21
+ page2 = Exstatic::Page.new(:title => "This is my second page", :slug => "foo", :content => "This is some content")
22
+ page2.valid?.should be_false
23
+ page2.errors[:slug].should_not be_nil
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ RailsApp::Application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,5 @@
1
+ class HomeController < ApplicationController
2
+ def custom_route
3
+ render
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1 @@
1
+ This is a custom page used for testing validation and saving of a new url slug