mist 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ spec/dummy_rails_app/log/*.log
16
16
  spec/dummy_rails_app/tmp
17
17
  spec/dummy_rails_app/db/mist.repo.*
18
18
  config/initializers/active_gist_credentials.rb
19
+ pkg
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mist (0.6.0)
4
+ mist (0.6.1)
5
5
  activegist (~> 0.6)
6
6
  git (~> 1.2)
7
7
  github-markup (~> 0.7)
@@ -9,11 +9,7 @@ class Mist::PostsController < ApplicationController
9
9
  # GET /posts
10
10
  # GET /posts.json
11
11
  def index
12
- if Mist.authorized? :view_drafts, self
13
- @posts = Mist::Post.last(20).reverse
14
- else
15
- @posts = Mist::Post.recently_published(20)
16
- end
12
+ @posts = Mist::Post.recently_published(20, Mist.authorized?(:view_drafts, self))
17
13
 
18
14
  respond_to do |format|
19
15
  format.html # index.html.erb
@@ -25,40 +25,51 @@ class Mist::Post < Mist::GitModel
25
25
  after_initialize :load_code_examples_from_gist
26
26
  after_destroy :destroy_gist
27
27
 
28
- def self.load_existing_with_attribute(attribute_name, array)
29
- array.collect { |(post_id, attribute_value)| find post_id, attribute_name => attribute_value }.reject { |i| i.nil? }
30
- end
28
+ class << self
29
+ def load_existing_with_attribute(attribute_name, array)
30
+ array.collect { |(post_id, attribute_value)| find post_id, attribute_name => attribute_value }.reject { |i| i.nil? }
31
+ end
31
32
 
32
- def self.most_popular(count)
33
- # invert <=> so that result is descending order
34
- load_existing_with_attribute :popularity, self[:popular_posts].sort { |a, b| -(a[1].to_i <=> b[1].to_i) }
35
- end
33
+ def most_popular(count)
34
+ # invert <=> so that result is descending order
35
+ load_existing_with_attribute :popularity, self[:popular_posts].sort { |a, b| -(a[1].to_i <=> b[1].to_i) }
36
+ end
36
37
 
37
- def self.increase_popularity(post)
38
- self[:popular_posts][post.id] = popularity_for(post.id) + 1
39
- save_meta_data :popular_posts
40
- post.popularity = self[:popular_posts][post.id]
41
- end
38
+ def increase_popularity(post)
39
+ self[:popular_posts][post.id] = popularity_for(post.id) + 1
40
+ save_meta_data :popular_posts
41
+ post.popularity = self[:popular_posts][post.id]
42
+ end
42
43
 
43
- def self.popularity_for(post_id)
44
- self[:popular_posts][post_id] || 0
45
- end
44
+ def popularity_for(post_id)
45
+ self[:popular_posts][post_id] || 0
46
+ end
46
47
 
47
- def self.recently_published(count)
48
- all_by_publication_date.tap do |result|
49
- result.pop while result.length > count
48
+ def recently_published(count, include_unpublished = false)
49
+ recent = all_by_publication_date(include_unpublished)
50
+ recent.tap do |result|
51
+ result.pop while result.length > count
52
+ end
50
53
  end
51
- end
52
54
 
53
- def self.all_by_publication_date
54
- # invert <=> so that result is descending order
55
- load_existing_with_attribute :published_at, self[:published_at].sort { |a, b| -(a[1] <=> b[1]) }
56
- end
55
+ def all_by_publication_date(include_unpublished = false)
56
+ publications = self[:published_at].sort do |(ka,va), (kb,vb)|
57
+ if va.nil?
58
+ vb.nil? ? 0 : -1
59
+ else
60
+ vb.nil? ? 1 : -(va <=> vb)
61
+ end
62
+ end
63
+
64
+ publications.select! { |(post, publish_date)| !publish_date.blank? } unless include_unpublished
65
+ load_existing_with_attribute :published_at, publications
66
+ end
57
67
 
58
- def self.matching_tags(tags)
59
- return [] if tags.blank?
60
- matches = self[:tags].inject({}) { |h,(k,v)| ((t = v.split(TAG_DELIM)) & tags).size > 0 ? h[k] = t : nil; h }
61
- load_existing_with_attribute :tags, matches.sort { |a, b| -((a[1] & tags).size <=> (b[1] & tags).size) }
68
+ def matching_tags(tags)
69
+ return [] if tags.blank?
70
+ matches = self[:tags].inject({}) { |h,(k,v)| ((t = v.split(TAG_DELIM)) & tags).size > 0 ? h[k] = t : nil; h }
71
+ load_existing_with_attribute :tags, matches.sort { |a, b| -((a[1] & tags).size <=> (b[1] & tags).size) }
72
+ end
62
73
  end
63
74
 
64
75
  def similar_posts(max_count = nil)
@@ -84,12 +95,8 @@ class Mist::Post < Mist::GitModel
84
95
  self.class.save_meta_data :popular_posts
85
96
  end
86
97
 
87
- if published_at_changed?
88
- if published_at.blank?
89
- self.class[:published_at].delete id
90
- else
91
- self.class[:published_at][id] = published_at
92
- end
98
+ if published_at_changed? || new_record?
99
+ self.class[:published_at][id] = published_at
93
100
  self.class.save_meta_data :published_at
94
101
  end
95
102
 
data/lib/mist/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Mist
2
2
  module Version
3
- MAJOR, MINOR, PATCH = 0, 6, 0
3
+ MAJOR, MINOR, PATCH = 0, 6, 1
4
4
  STRING = [MAJOR, MINOR, PATCH].join('.')
5
5
  end
6
6
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mist::PostsController do
4
- before { Mist.authorize :all do true end }
4
+ before { Mist.authorize { true } }
5
5
 
6
6
  # This should return the minimal set of attributes required to create a valid
7
7
  # Post. As you add validations to Post, be sure to
@@ -30,6 +30,31 @@ describe Mist::PostsController do
30
30
  get :index, {:use_route => :mist}, valid_session
31
31
  assigns(:posts).should eq([post])
32
32
  end
33
+
34
+ describe "with 7 posts" do
35
+ before do
36
+ @one = create(:post, :title => "one", :published_at => 1.day.ago)
37
+ @two = create(:post, :title => "two", :published_at => 5.days.ago)
38
+ @three = create(:post, :title => "three", :published_at => 1.day.from_now)
39
+ @four = create(:post, :title => "four", :published_at => nil)
40
+ @five = create(:post, :title => "five", :published_at => 2.days.from_now)
41
+ @six = create(:post, :title => "six", :published_at => Time.now)
42
+ @seven = create(:post, :title => "seven", :published_at => 2.days.ago)
43
+ end
44
+
45
+ it "assigns the posts in order" do
46
+ get :index, {:use_route => :mist}, valid_session
47
+ assigns(:posts).collect { |p| p.id }.should eq([@four.id, @five.id, @three.id, @six.id, @one.id, @seven.id, @two.id])
48
+ end
49
+
50
+ describe "when not authorized" do
51
+ before { Mist.authorize { false } }
52
+ it "assigns the posts in order, omitting unpublished" do
53
+ get :index, {:use_route => :mist}, valid_session
54
+ assigns(:posts).collect { |p| p.id }.should eq([@five.id, @three.id, @six.id, @one.id, @seven.id, @two.id])
55
+ end
56
+ end
57
+ end
33
58
  end
34
59
 
35
60
  describe "GET show" do
@@ -63,7 +63,11 @@ describe Mist::Post do
63
63
  describe "recent posts" do
64
64
  before do
65
65
  @order = [ 1.day.ago, 2.days.ago, 3.days.ago, 4.days.ago, 5.days.ago ]
66
- 5.times { |i| Mist::Post.create!(:title => "title#{i}", :content => "content", :published_at => @order[i]) }
66
+ Mist::Post.create!(:title => "title0", :content => "content", :published_at => @order[0])
67
+ Mist::Post.create!(:title => "title2", :content => "content", :published_at => @order[2])
68
+ Mist::Post.create!(:title => "title4", :content => "content", :published_at => @order[4])
69
+ Mist::Post.create!(:title => "title1", :content => "content", :published_at => @order[1])
70
+ Mist::Post.create!(:title => "title3", :content => "content", :published_at => @order[3])
67
71
  end
68
72
 
69
73
  it "should order by published_at descending" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-27 00:00:00.000000000Z
12
+ date: 2012-01-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: git
16
- requirement: &2162694360 !ruby/object:Gem::Requirement
16
+ requirement: &2155922540 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2162694360
24
+ version_requirements: *2155922540
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: github-markup
27
- requirement: &2162693740 !ruby/object:Gem::Requirement
27
+ requirement: &2155918340 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.7'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2162693740
35
+ version_requirements: *2155918340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: redcarpet
38
- requirement: &2162693140 !ruby/object:Gem::Requirement
38
+ requirement: &2155916640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '2.0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2162693140
46
+ version_requirements: *2155916640
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activegist
49
- requirement: &2162692460 !ruby/object:Gem::Requirement
49
+ requirement: &2155914440 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0.6'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2162692460
57
+ version_requirements: *2155914440
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: cucumber-rails
60
- requirement: &2162691800 !ruby/object:Gem::Requirement
60
+ requirement: &2155894500 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.2.1
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2162691800
68
+ version_requirements: *2155894500
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: database_cleaner
71
- requirement: &2162691020 !ruby/object:Gem::Requirement
71
+ requirement: &2154971300 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.7.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2162691020
79
+ version_requirements: *2154971300
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec-rails
82
- requirement: &2162690340 !ruby/object:Gem::Requirement
82
+ requirement: &2154970700 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 2.8.1
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2162690340
90
+ version_requirements: *2154970700
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: fakeweb
93
- requirement: &2162689660 !ruby/object:Gem::Requirement
93
+ requirement: &2154970240 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 1.3.0
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2162689660
101
+ version_requirements: *2154970240
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: factory_girl_rails
104
- requirement: &2162688920 !ruby/object:Gem::Requirement
104
+ requirement: &2154969740 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - =
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: 1.4.0
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2162688920
112
+ version_requirements: *2154969740
113
113
  description: a git-powered, gist-backed blogging engine for Rails 3
114
114
  email:
115
115
  - sinisterchipmunk@gmail.com
@@ -277,7 +277,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
277
277
  version: '0'
278
278
  segments:
279
279
  - 0
280
- hash: -2905108893950949948
280
+ hash: 915941666166025158
281
281
  required_rubygems_version: !ruby/object:Gem::Requirement
282
282
  none: false
283
283
  requirements:
@@ -286,7 +286,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
286
  version: '0'
287
287
  segments:
288
288
  - 0
289
- hash: -2905108893950949948
289
+ hash: 915941666166025158
290
290
  requirements: []
291
291
  rubyforge_project: mist
292
292
  rubygems_version: 1.8.10