Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Url (issue #59) #64

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ spec/dummy/tmp/
.DS_Store
.dropbox

.idea/

.idea/**/*

Gemfile.lock
2 changes: 1 addition & 1 deletion .rvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rvm use 1.9.3@monologue
rvm use 1.9.3@monologue --create
4 changes: 2 additions & 2 deletions app/controllers/monologue/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def index

def show
unless current_user
post = Monologue::Post.published.where("monologue_posts_revisions.url = :url", {:url => root_path + params[:post_url]}).first
post = Monologue::Post.published.where("monologue_posts_revisions.url = :url", {:url => params[:post_url]}).first
else
post = Monologue::Post.default.where("monologue_posts_revisions.url = :url", {:url => root_path + params[:post_url]}).first
post = Monologue::Post.default.where("monologue_posts_revisions.url = :url", {:url => params[:post_url]}).first
end
if post.nil?
not_found
Expand Down
6 changes: 5 additions & 1 deletion app/models/monologue/posts_revision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ def latest_revision_is_current
post.save!
end

def full_url
"#{Monologue::Engine.routes.url_helpers.root_path}#{self.url}"
end

private

def generate_url
year = self.published_at.class == ActiveSupport::TimeWithZone ? self.published_at.year : DateTime.now.year
self.title = "" if self.title.nil?
self.url = "#{Monologue::Engine.routes.url_helpers.root_path}#{year}/#{self.title.parameterize}" if self.url.nil? || self.url.strip == ""
self.url = "#{year}/#{self.title.parameterize}" if self.url.nil? || self.url.strip == ""
end
end
end
2 changes: 1 addition & 1 deletion app/views/monologue/admin/posts/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<% end %>
<%= post.check_box :published, :label => t(".published") %>

<%= post.submit t(".save"), :class => "btn btn-large btn-primary" %> <a href="<%= @revision.url %>" target="_blank" class="btn btn-large"><%= t(".preview") %></a>
<%= post.submit t(".save"), :class => "btn btn-large btn-primary" %> <a href="<%= @revision.full_url %>" target="_blank" class="btn btn-large"><%= t(".preview") %></a>

<script>
if($.fn.datepicker.defaults_<%= I18n.locale %>){
Expand Down
2 changes: 1 addition & 1 deletion app/views/monologue/posts/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<section>
<header>
<h1><%= link_to revision.title, revision.url %></h1>
<h1><%= link_to revision.title, revision.full_url %></h1>
<time datetime="<%= revision.published_at %>">
<%= revision.published_at.to_date.to_formatted_s(:long_ordinal) %>
</time>&nbsp;&nbsp;|&nbsp;&nbsp;<%= revision.user.name %>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="<%= revision.url + "#disqus_thread" %>"></a>
Expand Down
2 changes: 0 additions & 2 deletions spec/dummy/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ development:
pool: 5
username: root
password:
socket: /tmp/mysql.sock

test:
adapter: mysql2
Expand All @@ -16,7 +15,6 @@ test:
pool: 5
username: root
password:
socket: /tmp/mysql.sock

production:
adapter: sqlite3
Expand Down
8 changes: 4 additions & 4 deletions spec/factories/monologue_posts_and_revisions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
factory :posts_revision, :class => Monologue::PostsRevision do
sequence(:title) {|i| "post #{i} | revision 1"}
content "this is some text with french accents éàöûù and so on...even html tags like <br />"
sequence(:url) { |i| "/monologue/post/#{i}" }
sequence(:url) { |i| "post/#{i}" }
association :user
association :post
sequence(:published_at) {|i| DateTime.new(2012,1,1,12,0,17) + i.days }
end

factory :unpublished_post, :class => Monologue::Post, :parent => :post do |post|
published false
post.after_create { |p| Factory(:posts_revision, :post => p, :title => "unpublished", :url => "/monologue/unpublished") }
post.after_create { |p| Factory(:posts_revision, :post => p, :title => "unpublished", :url => "unpublished") }
end

factory :post_with_multiple_revisions, :class => Monologue::Post, :parent => :post do |post|
post.after_create { |p| Factory(:posts_revision, :post => p, :title => "post X | revision 1", :url => "/monologue/post/x") }
post.after_create { |p| Factory(:posts_revision, :post => p, :title => "post X | revision 2", :url => "/monologue/post/x") }
post.after_create { |p| Factory(:posts_revision, :post => p, :title => "post X | revision 1", :url => "post/x") }
post.after_create { |p| Factory(:posts_revision, :post => p, :title => "post X | revision 2", :url => "post/x") }
end
end
2 changes: 1 addition & 1 deletion spec/models/monologue/posts_revision_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
it "should create permalink (url) automaticly with title and year if none is provided" do
title = "this is a great title!!!"
post = Factory(:posts_revision, :url => "", :title => title, :published_at => "2012-02-02")
post.url.should == "/monologue/2012/this-is-a-great-title"
post.url.should == "2012/this-is-a-great-title"
end

it { validate_presence_of(:title) }
Expand Down
14 changes: 7 additions & 7 deletions spec/requests/cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@post_1 = Factory(:posts_revision).post
@post_2 = Factory(:posts_revision).post
@post_3 = Factory(:posts_revision).post
25.times { |i| Factory(:posts_revision, :title => "post #{i}", :url => "/monologue/post/#{i}") }
25.times { |i| Factory(:posts_revision, :title => "post #{i}", :url => "post/#{i}") }
ActionController::Base.perform_caching = true
clear_cache
end
Expand All @@ -31,7 +31,7 @@

describe "sweeper" do
before(:each) do
@test_paths = ["/monologue", @post_1.latest_revision.url, @post_2.latest_revision.url, @post_3.latest_revision.url]
@test_paths = ["/monologue","/monologue/#{@post_1.latest_revision.url}", "/monologue/#{@post_2.latest_revision.url}", "/monologue/#{@post_3.latest_revision.url}"]
@test_paths.each do |path|
assert_create_cache(path)
end
Expand All @@ -41,31 +41,31 @@
it "should clear cache on create" do
post = Factory(:post)
cache_sweeped?(["/monologue"]).should be_true
cache_sweeped?([@post_2.latest_revision.url, @post_3.latest_revision.url]).should be_false
cache_sweeped?(["/monologue/#{@post_2.latest_revision.url}", "/monologue/#{@post_3.latest_revision.url}"]).should be_false
cache_sweeped?([feed_path], "rss").should be_true
end

it "should clear cache on update" do
@post_1.save!
cache_sweeped?([@post_1.latest_revision.url]).should be_true
cache_sweeped?(["/monologue/"]).should be_true
cache_sweeped?([@post_2.latest_revision.url, @post_3.latest_revision.url]).should be_false
cache_sweeped?(["/monologue/#{@post_2.latest_revision.url}", "/monologue/#{@post_3.latest_revision.url}"]).should be_false
cache_sweeped?([feed_path], "rss").should be_true
end

it "should clear cache on destroy" do
@post_1.destroy
cache_sweeped?(["/monologue/"]).should be_true
cache_sweeped?([@post_2.latest_revision.url, @post_3.latest_revision.url]).should be_false
cache_sweeped?(["/monologue/#{@post_2.latest_revision.url}", "/monologue/#{@post_3.latest_revision.url}"]).should be_false
cache_sweeped?([feed_path], "rss").should be_true
end

it "won't clean cache if saving a not yet published post" do
@post_1.published = false
@post_1.save!
cache_sweeped?([@post_1.latest_revision.url]).should be_false
cache_sweeped?(["/monologue/#{@post_1.latest_revision.url}"]).should be_false
cache_sweeped?(["/monologue/"]).should be_false
cache_sweeped?([@post_2.latest_revision.url, @post_3.latest_revision.url]).should be_false
cache_sweeped?(["/monologue/#{@post_2.latest_revision.url}", "/monologue/#{@post_3.latest_revision.url}"]).should be_false
cache_sweeped?([feed_path], "rss").should be_false
end
end
Expand Down
5 changes: 3 additions & 2 deletions spec/requests/preview_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require 'spec_helper'
describe "preview" do
before(:each) do
@post_path = "/monologue/post/1"
url ="post/1"
@post_path = "/monologue/#{url}"
@post_title = "post 1 | revision 1"
Factory(:posts_revision, :title => @post_title, :url => @post_path)
Factory(:posts_revision, :title => @post_title, :url => url)
ActionController::Base.perform_caching = true
clear_cache
end
Expand Down