Merge branch 'refs/heads/snippets_expiration' into dev
Conflicts: db/schema.rb
This commit is contained in:
commit
89fa800e28
|
@ -1,2 +1,11 @@
|
||||||
module SnippetsHelper
|
module SnippetsHelper
|
||||||
|
def lifetime_select_options
|
||||||
|
options = [
|
||||||
|
['forever', nil],
|
||||||
|
['1 day', "#{Date.current + 1.day}"],
|
||||||
|
['1 week', "#{Date.current + 1.week}"],
|
||||||
|
['1 month', "#{Date.current + 1.month}"]
|
||||||
|
]
|
||||||
|
options_for_select(options)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,6 +22,9 @@ class Snippet < ActiveRecord::Base
|
||||||
:presence => true,
|
:presence => true,
|
||||||
:length => { :within => 0..10000 }
|
:length => { :within => 0..10000 }
|
||||||
|
|
||||||
|
scope :fresh, order("created_at DESC")
|
||||||
|
scope :non_expired, where(["expires_at IS NULL OR expires_at > ?", Time.current])
|
||||||
|
|
||||||
def self.content_types
|
def self.content_types
|
||||||
[
|
[
|
||||||
".rb", ".py", ".pl", ".scala", ".c", ".cpp", ".java",
|
".rb", ".py", ".pl", ".scala", ".c", ".cpp", ".java",
|
||||||
|
@ -33,6 +36,10 @@ class Snippet < ActiveRecord::Base
|
||||||
def colorize
|
def colorize
|
||||||
system_colorize(content, file_name)
|
system_colorize(content, file_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def expired?
|
||||||
|
expires_at && expires_at < Time.current
|
||||||
|
end
|
||||||
end
|
end
|
||||||
# == Schema Information
|
# == Schema Information
|
||||||
#
|
#
|
||||||
|
@ -46,5 +53,6 @@ end
|
||||||
# created_at :datetime
|
# created_at :datetime
|
||||||
# updated_at :datetime
|
# updated_at :datetime
|
||||||
# file_name :string(255)
|
# file_name :string(255)
|
||||||
|
# expires_at :datetime
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
= link_to project_snippets_path(@project), :class => (controller.controller_name == "snippets") ? "current" : nil do
|
= link_to project_snippets_path(@project), :class => (controller.controller_name == "snippets") ? "current" : nil do
|
||||||
Snippets
|
Snippets
|
||||||
- if @project.snippets.count > 0
|
- if @project.snippets.count > 0
|
||||||
%span{ :class => "top_menu_count" }= @project.snippets.count
|
%span{ :class => "top_menu_count" }= @project.snippets.non_expired.count
|
||||||
|
|
||||||
- if @commit
|
- if @commit
|
||||||
%span= link_to truncate(commit_name(@project,@commit), :length => 15), project_commit_path(@project, :id => @commit.id), :class => current_page?(:controller => "commits", :action => "show", :project_id => @project, :id => @commit.id) ? "current" : nil
|
%span= link_to truncate(commit_name(@project,@commit), :length => 15), project_commit_path(@project, :id => @commit.id), :class => current_page?(:controller => "commits", :action => "show", :project_id => @project, :id => @commit.id) ? "current" : nil
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
%tr
|
%tr
|
||||||
%td= f.label :file_name
|
%td= f.label :file_name
|
||||||
%td= f.text_field :file_name, :placeholder => "example.rb"
|
%td= f.text_field :file_name, :placeholder => "example.rb"
|
||||||
|
%tr
|
||||||
|
%td= f.label "Lifetime"
|
||||||
|
%td= f.select :expires_at, lifetime_select_options
|
||||||
%tr
|
%tr
|
||||||
%td{:colspan => 2}
|
%td{:colspan => 2}
|
||||||
= f.label :content, "Code"
|
= f.label :content, "Code"
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
- unless snippet.expired?
|
||||||
%tr{ :id => dom_id(snippet), :class => "snippet", :url => project_snippet_path(@project, snippet) }
|
%tr{ :id => dom_id(snippet), :class => "snippet", :url => project_snippet_path(@project, snippet) }
|
||||||
%td
|
%td
|
||||||
= image_tag gravatar_icon(snippet.author.email), :class => "left", :width => 40, :style => "padding:0 5px;"
|
= image_tag gravatar_icon(snippet.author.email), :class => "left", :width => 40, :style => "padding:0 5px;"
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
%th Title
|
%th Title
|
||||||
%th File name
|
%th File name
|
||||||
%th
|
%th
|
||||||
= render @snippets
|
= render @snippets.fresh
|
||||||
:javascript
|
:javascript
|
||||||
$('.delete-snippet').live('ajax:success', function() {
|
$('.delete-snippet').live('ajax:success', function() {
|
||||||
$(this).closest('tr').fadeOut(); });
|
$(this).closest('tr').fadeOut(); });
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
- if !@snippet.expired?
|
||||||
%h2
|
%h2
|
||||||
= "Snippet ##{@snippet.id} - #{@snippet.title}"
|
= "Snippet ##{@snippet.id} - #{@snippet.title}"
|
||||||
|
|
||||||
|
@ -20,3 +21,6 @@
|
||||||
|
|
||||||
.clear
|
.clear
|
||||||
|
|
||||||
|
- else
|
||||||
|
%h2
|
||||||
|
Sorry, this snippet is no longer exists
|
||||||
|
|
5
db/migrate/20111027051828_add_expires_at_to_snippets.rb
Normal file
5
db/migrate/20111027051828_add_expires_at_to_snippets.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddExpiresAtToSnippets < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :snippets, :expires_at, :datetime
|
||||||
|
end
|
||||||
|
end
|
|
@ -65,6 +65,7 @@ ActiveRecord::Schema.define(:version => 20111027142641) do
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "file_name"
|
t.string "file_name"
|
||||||
|
t.datetime "expires_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "users", :force => true do |t|
|
create_table "users", :force => true do |t|
|
||||||
|
|
|
@ -26,5 +26,6 @@ end
|
||||||
# created_at :datetime
|
# created_at :datetime
|
||||||
# updated_at :datetime
|
# updated_at :datetime
|
||||||
# file_name :string(255)
|
# file_name :string(255)
|
||||||
|
# expires_at :datetime
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,14 @@ describe "Snippets" do
|
||||||
it { should have_content(@snippet.project.name) }
|
it { should have_content(@snippet.project.name) }
|
||||||
it { should have_content(@snippet.author.name) }
|
it { should have_content(@snippet.author.name) }
|
||||||
|
|
||||||
|
it "doesn't show expired snippets" do
|
||||||
|
@snippet.update_attribute(:expires_at, 1.day.ago.to_time)
|
||||||
|
visit project_snippet_path(project, @snippet)
|
||||||
|
page.should have_content("Sorry, this snippet is no longer exists")
|
||||||
|
page.should_not have_content(@snippet.title)
|
||||||
|
page.should_not have_content(@snippet.content)
|
||||||
|
end
|
||||||
|
|
||||||
describe "Destroy" do
|
describe "Destroy" do
|
||||||
before do
|
before do
|
||||||
# admin access to remove snippet
|
# admin access to remove snippet
|
||||||
|
|
Loading…
Reference in a new issue