Skip to content
This repository

Url (issue #59) #64

Closed
wants to merge 3 commits into from

2 participants

Michael Sevestre Jean-Philippe Boily
Michael Sevestre
Collaborator

All right. That should fix the url issue for issue #59
However, all old previous url are not compatible anymore if the blog was not mounted under /

Jean-Philippe Boily
Owner

How would you handle upgrades? A migration? Just an upgrade instruction? Maybe in a UPGRADE.md and specified in the CHANGELOG.md?

I would probably do a migration. Your thoughts?

Michael Sevestre
Collaborator

Migration would be ideal. (it would just remove the // from any url if required.
On the other hand, an upgrade.md file might be enough. We could also provide a rake task that would do the migration. The user would be in charged of running the rake file if required

Jean-Philippe Boily
Owner

This was merged here 096ee35

I also added a migration (832ea73), changed tips in UI (7e7f51b) and added a UPGRADE.md file to help people with upgrades(5b6bbac).

Jean-Philippe Boily jipiboily closed this May 26, 2012
Jean-Philippe Boily
Owner

Thanks a lot Michael!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
4  .gitignore
@@ -9,4 +9,8 @@ spec/dummy/tmp/
9 9
 .DS_Store
10 10
 .dropbox
11 11
 
  12
+.idea/
  13
+
  14
+.idea/**/*
  15
+
12 16
 Gemfile.lock
2  .rvmrc
... ...
@@ -1 +1 @@
1  
-rvm use 1.9.3@monologue
  1
+rvm use 1.9.3@monologue --create
4  app/controllers/monologue/posts_controller.rb
@@ -8,9 +8,9 @@ def index
8 8
   
9 9
   def show
10 10
     unless current_user
11  
-      post = Monologue::Post.published.where("monologue_posts_revisions.url = :url", {:url => root_path + params[:post_url]}).first
  11
+      post = Monologue::Post.published.where("monologue_posts_revisions.url = :url", {:url => params[:post_url]}).first
12 12
     else
13  
-      post = Monologue::Post.default.where("monologue_posts_revisions.url = :url", {:url => root_path + params[:post_url]}).first
  13
+      post = Monologue::Post.default.where("monologue_posts_revisions.url = :url", {:url => params[:post_url]}).first
14 14
     end
15 15
     if post.nil?
16 16
       not_found
6  app/models/monologue/posts_revision.rb
@@ -23,12 +23,16 @@ def latest_revision_is_current
23 23
       post.save!
24 24
     end
25 25
 
  26
+    def full_url
  27
+      "#{Monologue::Engine.routes.url_helpers.root_path}#{self.url}"
  28
+    end
  29
+
26 30
     private 
27 31
 
28 32
       def generate_url
29 33
         year = self.published_at.class == ActiveSupport::TimeWithZone ? self.published_at.year : DateTime.now.year
30 34
         self.title = "" if self.title.nil?
31  
-        self.url = "#{Monologue::Engine.routes.url_helpers.root_path}#{year}/#{self.title.parameterize}" if self.url.nil? || self.url.strip == ""
  35
+        self.url = "#{year}/#{self.title.parameterize}" if self.url.nil? || self.url.strip == ""
32 36
       end
33 37
   end
34 38
 end
2  app/views/monologue/admin/posts/_form.html.erb
@@ -7,7 +7,7 @@
7 7
 <% end %>
8 8
 <%= post.check_box :published, :label =>  t(".published") %>
9 9
 
10  
-<%= post.submit t(".save"), :class =>  "btn btn-large btn-primary" %> <a href="<%= @revision.url %>" target="_blank" class="btn btn-large"><%= t(".preview") %></a>
  10
+<%= post.submit t(".save"), :class =>  "btn btn-large btn-primary" %> <a href="<%= @revision.full_url %>" target="_blank" class="btn btn-large"><%= t(".preview") %></a>
11 11
 
12 12
 <script>
13 13
   if($.fn.datepicker.defaults_<%= I18n.locale %>){
2  app/views/monologue/posts/index.html.erb
@@ -3,7 +3,7 @@
3 3
   
4 4
   <section>
5 5
     <header>
6  
-      <h1><%= link_to revision.title, revision.url %></h1>
  6
+      <h1><%= link_to revision.title, revision.full_url %></h1>
7 7
       <time datetime="<%= revision.published_at %>">
8 8
         <%= revision.published_at.to_date.to_formatted_s(:long_ordinal) %>
9 9
       </time>&nbsp;&nbsp;|&nbsp;&nbsp;<%= revision.user.name %>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="<%= revision.url + "#disqus_thread" %>"></a>
2  spec/dummy/config/database.yml
@@ -6,7 +6,6 @@ development:
6 6
   pool: 5
7 7
   username: root
8 8
   password:
9  
-  socket: /tmp/mysql.sock
10 9
 
11 10
 test:
12 11
   adapter: mysql2
@@ -16,7 +15,6 @@ test:
16 15
   pool: 5
17 16
   username: root
18 17
   password:
19  
-  socket: /tmp/mysql.sock
20 18
 
21 19
 production:
22 20
   adapter: sqlite3
8  spec/factories/monologue_posts_and_revisions.rb
@@ -7,7 +7,7 @@
7 7
   factory :posts_revision, :class =>  Monologue::PostsRevision do
8 8
     sequence(:title) {|i| "post #{i} | revision 1"}
9 9
     content "this is some text with french accents éàöûù and so on...even html tags like <br />"
10  
-    sequence(:url) { |i| "/monologue/post/#{i}" }
  10
+    sequence(:url) { |i| "post/#{i}" }
11 11
     association :user
12 12
     association :post
13 13
     sequence(:published_at) {|i| DateTime.new(2012,1,1,12,0,17) + i.days }
@@ -15,11 +15,11 @@
15 15
 
16 16
   factory :unpublished_post, :class =>  Monologue::Post, :parent => :post do |post|
17 17
     published false
18  
-    post.after_create { |p| Factory(:posts_revision, :post => p, :title => "unpublished", :url => "/monologue/unpublished") }
  18
+    post.after_create { |p| Factory(:posts_revision, :post => p, :title => "unpublished", :url => "unpublished") }
19 19
   end
20 20
 
21 21
   factory :post_with_multiple_revisions, :class =>  Monologue::Post, :parent => :post do |post|
22  
-    post.after_create { |p| Factory(:posts_revision, :post => p, :title => "post X | revision 1", :url => "/monologue/post/x") }
23  
-    post.after_create { |p| Factory(:posts_revision, :post => p, :title => "post X | revision 2", :url => "/monologue/post/x") }
  22
+    post.after_create { |p| Factory(:posts_revision, :post => p, :title => "post X | revision 1", :url => "post/x") }
  23
+    post.after_create { |p| Factory(:posts_revision, :post => p, :title => "post X | revision 2", :url => "post/x") }
24 24
   end
25 25
 end
2  spec/models/monologue/posts_revision_spec.rb
@@ -25,7 +25,7 @@
25 25
   it "should create permalink (url) automaticly with title and year if none is provided" do
26 26
     title = "this is a great title!!!"
27 27
     post = Factory(:posts_revision, :url => "", :title => title, :published_at => "2012-02-02")
28  
-    post.url.should == "/monologue/2012/this-is-a-great-title"
  28
+    post.url.should == "2012/this-is-a-great-title"
29 29
   end
30 30
 
31 31
   it { validate_presence_of(:title) }
14  spec/requests/cache_spec.rb
@@ -5,7 +5,7 @@
5 5
     @post_1 = Factory(:posts_revision).post
6 6
     @post_2 = Factory(:posts_revision).post
7 7
     @post_3 = Factory(:posts_revision).post
8  
-    25.times { |i| Factory(:posts_revision, :title => "post #{i}", :url => "/monologue/post/#{i}") }
  8
+    25.times { |i| Factory(:posts_revision, :title => "post #{i}", :url => "post/#{i}") }
9 9
     ActionController::Base.perform_caching = true
10 10
     clear_cache
11 11
   end
@@ -31,7 +31,7 @@
31 31
 
32 32
   describe "sweeper" do 
33 33
     before(:each) do
34  
-      @test_paths = ["/monologue", @post_1.latest_revision.url, @post_2.latest_revision.url, @post_3.latest_revision.url]
  34
+      @test_paths = ["/monologue","/monologue/#{@post_1.latest_revision.url}", "/monologue/#{@post_2.latest_revision.url}", "/monologue/#{@post_3.latest_revision.url}"]
35 35
       @test_paths.each do |path|
36 36
         assert_create_cache(path)
37 37
       end
@@ -41,7 +41,7 @@
41 41
     it "should clear cache on create" do
42 42
       post = Factory(:post)
43 43
       cache_sweeped?(["/monologue"]).should be_true
44  
-      cache_sweeped?([@post_2.latest_revision.url, @post_3.latest_revision.url]).should be_false
  44
+      cache_sweeped?(["/monologue/#{@post_2.latest_revision.url}", "/monologue/#{@post_3.latest_revision.url}"]).should be_false
45 45
       cache_sweeped?([feed_path], "rss").should be_true
46 46
     end 
47 47
 
@@ -49,23 +49,23 @@
49 49
       @post_1.save!
50 50
       cache_sweeped?([@post_1.latest_revision.url]).should be_true
51 51
       cache_sweeped?(["/monologue/"]).should be_true
52  
-      cache_sweeped?([@post_2.latest_revision.url, @post_3.latest_revision.url]).should be_false
  52
+      cache_sweeped?(["/monologue/#{@post_2.latest_revision.url}", "/monologue/#{@post_3.latest_revision.url}"]).should be_false
53 53
       cache_sweeped?([feed_path], "rss").should be_true
54 54
     end
55 55
 
56 56
     it "should clear cache on destroy" do
57 57
       @post_1.destroy
58 58
       cache_sweeped?(["/monologue/"]).should be_true
59  
-      cache_sweeped?([@post_2.latest_revision.url, @post_3.latest_revision.url]).should be_false
  59
+      cache_sweeped?(["/monologue/#{@post_2.latest_revision.url}", "/monologue/#{@post_3.latest_revision.url}"]).should be_false
60 60
       cache_sweeped?([feed_path], "rss").should be_true
61 61
     end
62 62
 
63 63
     it "won't clean cache if saving a not yet published post" do
64 64
       @post_1.published = false
65 65
       @post_1.save!
66  
-      cache_sweeped?([@post_1.latest_revision.url]).should be_false
  66
+      cache_sweeped?(["/monologue/#{@post_1.latest_revision.url}"]).should be_false
67 67
       cache_sweeped?(["/monologue/"]).should be_false
68  
-      cache_sweeped?([@post_2.latest_revision.url, @post_3.latest_revision.url]).should be_false
  68
+      cache_sweeped?(["/monologue/#{@post_2.latest_revision.url}", "/monologue/#{@post_3.latest_revision.url}"]).should be_false
69 69
       cache_sweeped?([feed_path], "rss").should be_false
70 70
     end
71 71
   end
5  spec/requests/preview_spec.rb
... ...
@@ -1,9 +1,10 @@
1 1
 require 'spec_helper'
2 2
 describe "preview" do
3 3
   before(:each) do
4  
-    @post_path = "/monologue/post/1"
  4
+    url ="post/1"
  5
+    @post_path = "/monologue/#{url}"
5 6
     @post_title = "post 1 | revision 1"
6  
-    Factory(:posts_revision, :title => @post_title, :url => @post_path)
  7
+    Factory(:posts_revision, :title => @post_title, :url => url)
7 8
     ActionController::Base.perform_caching = true
8 9
     clear_cache
9 10
   end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.