aguids-publishable 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.2
@@ -0,0 +1,37 @@
1
+ class PublicationsController < ApplicationController
2
+
3
+ def create
4
+ if unpublished_resource.publish!
5
+ flash[:notice] = I18n.t('flash.publications.create.notice', :default => "#{resource.class.human_name} published successfully")
6
+ end
7
+ respond_to do |format|
8
+ format.html {redirect_to :back}
9
+ end
10
+ end
11
+
12
+ def destroy
13
+ if published_resource.unpublish!
14
+ flash[:notice] = I18n.t('flash.publications.destroy.notice', :default => "#{resource.class.human_name} unpublished successfully")
15
+ end
16
+ respond_to do |format|
17
+ format.html {redirect_to :back}
18
+ end
19
+ end
20
+
21
+ protected
22
+ def unpublished_resource
23
+ @resource ||= resource_class.unpublished.find(params[:id])
24
+ end
25
+
26
+ def published_resource
27
+ @resource ||= resource_class.published.find(params[:id])
28
+ end
29
+
30
+ def resource
31
+ @resource
32
+ end
33
+
34
+ def resource_class
35
+ params[:resource].camelize.constantize
36
+ end
37
+ end
@@ -0,0 +1,39 @@
1
+ module PublicationsHelper
2
+ def publish_path(resource, options = {})
3
+ url_for({:controller => 'publications', :action => 'create',
4
+ :resource => resource.class.to_s.underscore, :id => resource.id}.merge(options))
5
+ end
6
+
7
+ def publish_url(resource, options = {})
8
+ publish_path(resource, options.merge({ :only_path => false }))
9
+ end
10
+
11
+ def unpublish_path(resource, options = {})
12
+ url_for({:controller => 'publications', :action => 'destroy',
13
+ :resource => resource.class.to_s.underscore, :id => resource.id}.merge(options))
14
+ end
15
+
16
+ def unpublish_url(resource, options = {})
17
+ unpublish_path(resource, options.merge({ :only_path => false }))
18
+ end
19
+
20
+ def publication_links(resource)
21
+ tag = '<ul class="publication_links">'
22
+ if resource.unpublished?
23
+ tag << "<li>" << link_to(I18n.t('publications.publish', :default => 'Publish'), publish_path(resource)) << "</li>"
24
+ tag << '<li class="unpublish_disabled">' << I18n.t('publications.unpublish', :default => 'Unpublish') << '</li>'
25
+ else
26
+ tag << '<li class="publish_disabled">' << I18n.t('publications.publish', :default => 'Publish') << '</li>'
27
+ tag << "<li>" << link_to(I18n.t('publications.unpublish', :default => 'Unpublish'), unpublish_path(resource)) << "</li>"
28
+ end
29
+ tag
30
+ end
31
+
32
+ def publication_link(resource)
33
+ if resource.unpublished?
34
+ link_to I18n.t('publications.publish', :default => 'Publish'), publish_path(resource), :method => :post
35
+ else
36
+ link_to I18n.t('publications.unpublish', :default => 'Unpublish'), unpublish_path(resource), :method => :delete
37
+ end
38
+ end
39
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ map.connect ':resource/:id/publish', :controller => 'publications', :action => 'create', :conditions => {:method => :post}
3
+ map.connect ':resource/:id/unpublish', :controller => 'publications', :action => 'destroy', :conditions => {:method => :delete}
4
+ end
@@ -0,0 +1,122 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{publishable}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Felipe Doria"]
9
+ s.date = %q{2009-08-01}
10
+ s.email = %q{felipe.doria@gmail.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "app/controllers/publications_controller.rb",
23
+ "app/helpers/publications_helper.rb",
24
+ "config/routes.rb",
25
+ "init.rb",
26
+ "lib/publishable.rb",
27
+ "publishable.gemspec",
28
+ "test/rails_root/Rakefile",
29
+ "test/rails_root/app/controllers/application_controller.rb",
30
+ "test/rails_root/app/helpers/application_helper.rb",
31
+ "test/rails_root/app/models/post.rb",
32
+ "test/rails_root/app/models/published_post.rb",
33
+ "test/rails_root/config/boot.rb",
34
+ "test/rails_root/config/database.yml",
35
+ "test/rails_root/config/environment.rb",
36
+ "test/rails_root/config/environments/development.rb",
37
+ "test/rails_root/config/environments/production.rb",
38
+ "test/rails_root/config/environments/test.rb",
39
+ "test/rails_root/config/initializers/backtrace_silencers.rb",
40
+ "test/rails_root/config/initializers/inflections.rb",
41
+ "test/rails_root/config/initializers/mime_types.rb",
42
+ "test/rails_root/config/initializers/new_rails_defaults.rb",
43
+ "test/rails_root/config/initializers/session_store.rb",
44
+ "test/rails_root/config/locales/en.yml",
45
+ "test/rails_root/config/routes.rb",
46
+ "test/rails_root/db/migrate/20090731062231_create_posts.rb",
47
+ "test/rails_root/db/migrate/20090731073912_create_published_posts.rb",
48
+ "test/rails_root/db/schema.rb",
49
+ "test/rails_root/public/404.html",
50
+ "test/rails_root/public/422.html",
51
+ "test/rails_root/public/500.html",
52
+ "test/rails_root/public/favicon.ico",
53
+ "test/rails_root/public/images/rails.png",
54
+ "test/rails_root/public/index.html",
55
+ "test/rails_root/public/javascripts/application.js",
56
+ "test/rails_root/public/javascripts/controls.js",
57
+ "test/rails_root/public/javascripts/dragdrop.js",
58
+ "test/rails_root/public/javascripts/effects.js",
59
+ "test/rails_root/public/javascripts/prototype.js",
60
+ "test/rails_root/public/robots.txt",
61
+ "test/rails_root/script/about",
62
+ "test/rails_root/script/console",
63
+ "test/rails_root/script/dbconsole",
64
+ "test/rails_root/script/destroy",
65
+ "test/rails_root/script/generate",
66
+ "test/rails_root/script/performance/benchmarker",
67
+ "test/rails_root/script/performance/profiler",
68
+ "test/rails_root/script/plugin",
69
+ "test/rails_root/script/runner",
70
+ "test/rails_root/script/server",
71
+ "test/rails_root/test/functional/publications_controller_test.rb",
72
+ "test/rails_root/test/performance/browsing_test.rb",
73
+ "test/rails_root/test/test_helper.rb",
74
+ "test/rails_root/test/unit/helpers/publications_helper_test.rb",
75
+ "test/rails_root/test/unit/post_test.rb",
76
+ "test/rails_root/test/unit/published_post_test.rb"
77
+ ]
78
+ s.homepage = %q{http://github.com/aguids/publishable}
79
+ s.rdoc_options = ["--charset=UTF-8"]
80
+ s.require_paths = ["lib"]
81
+ s.rubygems_version = %q{1.3.4}
82
+ s.summary = %q{Rails engine for publishing behavior. Depends on AASM.}
83
+ s.test_files = [
84
+ "test/rails_root/app/controllers/application_controller.rb",
85
+ "test/rails_root/app/helpers/application_helper.rb",
86
+ "test/rails_root/app/models/post.rb",
87
+ "test/rails_root/app/models/published_post.rb",
88
+ "test/rails_root/config/boot.rb",
89
+ "test/rails_root/config/environment.rb",
90
+ "test/rails_root/config/environments/development.rb",
91
+ "test/rails_root/config/environments/production.rb",
92
+ "test/rails_root/config/environments/test.rb",
93
+ "test/rails_root/config/initializers/backtrace_silencers.rb",
94
+ "test/rails_root/config/initializers/inflections.rb",
95
+ "test/rails_root/config/initializers/mime_types.rb",
96
+ "test/rails_root/config/initializers/new_rails_defaults.rb",
97
+ "test/rails_root/config/initializers/session_store.rb",
98
+ "test/rails_root/config/routes.rb",
99
+ "test/rails_root/db/migrate/20090731062231_create_posts.rb",
100
+ "test/rails_root/db/migrate/20090731073912_create_published_posts.rb",
101
+ "test/rails_root/db/schema.rb",
102
+ "test/rails_root/test/functional/publications_controller_test.rb",
103
+ "test/rails_root/test/performance/browsing_test.rb",
104
+ "test/rails_root/test/test_helper.rb",
105
+ "test/rails_root/test/unit/helpers/publications_helper_test.rb",
106
+ "test/rails_root/test/unit/post_test.rb",
107
+ "test/rails_root/test/unit/published_post_test.rb"
108
+ ]
109
+
110
+ if s.respond_to? :specification_version then
111
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
112
+ s.specification_version = 3
113
+
114
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
115
+ s.add_runtime_dependency(%q<rubyist-aasm>, [">= 1.3.4"])
116
+ else
117
+ s.add_dependency(%q<rubyist-aasm>, [">= 1.3.4"])
118
+ end
119
+ else
120
+ s.add_dependency(%q<rubyist-aasm>, [">= 1.3.4"])
121
+ end
122
+ end
@@ -0,0 +1,109 @@
1
+ require 'test_helper'
2
+
3
+ class PublicationsControllerTest < ActionController::TestCase
4
+ def setup
5
+ @request.env["HTTP_REFERER"] = '/'
6
+ end
7
+
8
+ # Routes
9
+ test "route should match publish" do
10
+ assert_routing( {:method => 'post', :path => 'resource/17/publish'}, {:controller => 'publications', :action => 'create', :id => '17', :resource => 'resource'})
11
+ end
12
+
13
+ test "route should match unpublish" do
14
+ assert_routing( {:method => 'delete', :path => 'resource/17/unpublish'}, {:controller => 'publications', :action => 'destroy', :id => '17', :resource => 'resource'})
15
+ end
16
+
17
+ test "create with publishable resource should redirect back" do
18
+ @post = create_post(:title => 'Name')
19
+ post :create, :resource => 'post', :id => @post.id
20
+ assert_redirected_to '/'
21
+ end
22
+
23
+ test "create with publishable resource should publish" do
24
+ @post = create_post(:title => 'Name')
25
+ post :create, :resource => 'post', :id => @post.id
26
+ assert_not_nil assigns(:resource)
27
+ assert_equal @post, assigns(:resource)
28
+ assert assigns(:resource).published?
29
+ end
30
+
31
+ test "create with publishable resource should set the flash" do
32
+ @post = create_post(:title => 'Name')
33
+ post :create, :resource => 'post', :id => @post.id
34
+ assert_not_nil flash[:notice]
35
+ end
36
+
37
+ test "create with publishable resource should accept I18n translations for flash" do
38
+ I18n.backend.store_translations :en, :flash => { :publications => { :create => { :notice => 'Test Message' }}}
39
+ @post = create_post(:title => 'Name')
40
+ post :create, :resource => 'post', :id => @post.id
41
+ assert_equal 'Test Message', flash[:notice]
42
+ end
43
+
44
+ test "create with unpublishable resource should redirect back" do
45
+ @post = create_post
46
+ post :create, :resource => 'post', :id => @post.id
47
+ assert_redirected_to '/'
48
+ end
49
+
50
+ test "create with unpublishable resource should not publish" do
51
+ @post = create_post
52
+ post :create, :resource => 'post', :id => @post.id
53
+ assert_not_nil assigns(:resource)
54
+ assert_equal @post, assigns(:resource)
55
+ assert !assigns(:resource).published?
56
+ end
57
+
58
+ test "create with unpublishable resource should not set flash" do
59
+ @post = create_post
60
+ post :create, :resource => 'post', :id => @post.id
61
+ assert flash.empty?
62
+ end
63
+
64
+ test "create with published resource should raise an error" do
65
+ @post = create_post(:title => 'Name')
66
+ @post.publish!
67
+ assert_raise ActiveRecord::RecordNotFound do
68
+ post :create, :resource => 'post', :id => @post.id
69
+ end
70
+ end
71
+
72
+ test "destroy with published resource should redirect back" do
73
+ @post = create_post(:title => 'Name')
74
+ @post.publish!
75
+ delete :destroy, :resource => 'post', :id => @post.id
76
+ assert_redirected_to '/'
77
+ end
78
+
79
+ test "destroy with published resource should unpublish" do
80
+ @post = create_post(:title => 'Name')
81
+ @post.publish!
82
+ delete :destroy, :resource => 'post', :id => @post.id
83
+ assert_not_nil assigns(:resource)
84
+ assert_equal @post, assigns(:resource)
85
+ assert assigns(:resource).unpublished?
86
+ end
87
+
88
+ test "destroy with published resource should set flash" do
89
+ @post = create_post(:title => 'Name')
90
+ @post.publish!
91
+ delete :destroy, :resource => 'post', :id => @post.id
92
+ assert_not_nil flash[:notice]
93
+ end
94
+
95
+ test "destroy with published resource should accept I18n translations for flash" do
96
+ I18n.backend.store_translations :en, :flash => { :publications => { :destroy => { :notice => 'Test Message' }}}
97
+ @post = create_post(:title => 'Name')
98
+ @post.publish!
99
+ delete :destroy, :resource => 'post', :id => @post.id
100
+ assert_equal 'Test Message', flash[:notice]
101
+ end
102
+
103
+ test "destroy with unpublished resource should raise an error" do
104
+ @post = create_post
105
+ assert_raise ActiveRecord::RecordNotFound do
106
+ delete :destroy, :resource => 'post', :id => @post.id
107
+ end
108
+ end
109
+ end
@@ -3,36 +3,17 @@ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
3
  require 'test_help'
4
4
 
5
5
  class ActiveSupport::TestCase
6
- # Transactional fixtures accelerate your tests by wrapping each test method
7
- # in a transaction that's rolled back on completion. This ensures that the
8
- # test database remains unchanged so your fixtures don't have to be reloaded
9
- # between every test method. Fewer database queries means faster tests.
10
- #
11
- # Read Mike Clark's excellent walkthrough at
12
- # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
13
- #
14
- # Every Active Record database supports transactions except MyISAM tables
15
- # in MySQL. Turn off transactional fixtures in this case; however, if you
16
- # don't care one way or the other, switching from MyISAM to InnoDB tables
17
- # is recommended.
18
- #
19
- # The only drawback to using transactional fixtures is when you actually
20
- # need to test transactions. Since your test is bracketed by a transaction,
21
- # any transactions started in your code will be automatically rolled back.
22
6
  self.use_transactional_fixtures = true
23
-
24
- # Instantiated fixtures are slow, but give you @david where otherwise you
25
- # would need people(:david). If you don't want to migrate your existing
26
- # test cases which use the @david style and don't mind the speed hit (each
27
- # instantiated fixtures translates to a database query per test method),
28
- # then set this back to true.
29
7
  self.use_instantiated_fixtures = false
30
-
31
- # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
32
- #
33
- # Note: You'll currently still have to declare fixtures explicitly in integration tests
34
- # -- they do not yet inherit this setting
35
8
  fixtures :all
36
9
 
37
10
  # Add more helper methods to be used by all tests here...
11
+
12
+ def create_post(options = {})
13
+ Post.create(options)
14
+ end
15
+
16
+ def create_published_post
17
+ PublishedPost.create
18
+ end
38
19
  end
@@ -0,0 +1,91 @@
1
+ require 'test_helper'
2
+
3
+ class PublicationsHelperTest < ActionView::TestCase
4
+ def protect_against_forgery?
5
+ end
6
+
7
+ def setup
8
+ @host = 'http://test.host'
9
+ @post = create_post(:title => 'Title')
10
+ @controller = TestController.new
11
+ end
12
+
13
+ def teardown
14
+ I18n.backend.store_translations :en, :publications => nil
15
+ end
16
+
17
+ [:publish, :unpublish].each do |action|
18
+ test "#{action} path and url" do
19
+ path = "/post/#{@post.id}/#{action}"
20
+ assert_equal path, send("#{action}_path", @post)
21
+ assert_equal "#{@host}#{path}", send("#{action}_url", @post)
22
+ end
23
+ end
24
+
25
+ test "publication links should have a ul container" do
26
+ html = publication_links(@post)
27
+ assert_match '<ul class="publication_links">', html
28
+ end
29
+
30
+ test "publication links should return link to publish if unpublished" do
31
+ html = publication_links(@post)
32
+ assert_match /<a href="[^"]*".*Publish/i, html
33
+ end
34
+
35
+ test "publication links should return link to unpublish if published" do
36
+ @post.publish!
37
+ html = publication_links(@post)
38
+ assert_match /<a href="[^"]*".*Unpublish/i, html
39
+ end
40
+
41
+ test "publication links should return publish disabled if published" do
42
+ @post.publish!
43
+ html = publication_links(@post)
44
+ assert_match /<li class="publish_disabled">Publish/i, html
45
+ end
46
+
47
+ test "publication links should return unpublish disabled if unpublished" do
48
+ html = publication_links(@post)
49
+ assert_match /<li class="unpublish_disabled">Unpublish/i, html
50
+ end
51
+
52
+ test "publication links should accept I18n translations if unpublished" do
53
+ I18n.backend.store_translations :en, :publications => { :publish => 'Publish Test Message', :unpublish => 'Unpublish Test Message' }
54
+ html = publication_links(@post)
55
+ assert_match /<a href="[^"]*".*Publish Test Message/i, html
56
+ assert_match /<li class="unpublish_disabled">Unpublish Test Message/i, html
57
+ end
58
+
59
+ test "publication links should accept I18n translations if published" do
60
+ I18n.backend.store_translations :en, :publications => { :publish => 'Publish Test Message', :unpublish => 'Unpublish Test Message' }
61
+ @post.publish!
62
+ html = publication_links(@post)
63
+ assert_match /<a href="[^"]*".*Unpublish Test Message/i, html
64
+ assert_match /<li class="publish_disabled">Publish Test Message/i, html
65
+ end
66
+
67
+ # Solo Helper
68
+ test "publication link should return publish if unpublished" do
69
+ html = publication_link(@post)
70
+ assert_match /<a href="[^"]*".*Publish/i, html
71
+ end
72
+
73
+ test "publication link should return unpublish if published" do
74
+ @post.publish!
75
+ html = publication_link(@post)
76
+ assert_match /<a href="[^"]*".*Unpublish/i, html
77
+ end
78
+
79
+ test "publication link should accept I18n translations on publish" do
80
+ I18n.backend.store_translations :en, :publications => { :publish => 'Test Message' }
81
+ html = publication_link(@post)
82
+ assert_match /Test Message/i, html
83
+ end
84
+
85
+ test "publication link should accept I18n translations on unpublish" do
86
+ @post.publish!
87
+ I18n.backend.store_translations :en, :publications => { :unpublish => 'Test Message' }
88
+ html = publication_link(@post)
89
+ assert_match /Test Message/i, html
90
+ end
91
+ end
@@ -42,8 +42,4 @@ class PostTest < ActiveSupport::TestCase
42
42
  @post.publish
43
43
  assert !@post.valid?
44
44
  end
45
-
46
- def create_post(options = {})
47
- Post.create(options)
48
- end
49
45
  end
@@ -2,15 +2,11 @@ require 'test_helper'
2
2
 
3
3
  class PublishedPostTest < ActiveSupport::TestCase
4
4
  def setup
5
- @post = create_post
5
+ @post = create_published_post
6
6
  end
7
7
 
8
8
  test "should start published" do
9
9
  assert @post.published?
10
10
  assert !@post.unpublished?
11
11
  end
12
-
13
- def create_post
14
- PublishedPost.create
15
- end
16
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aguids-publishable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Doria
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-31 00:00:00 -07:00
12
+ date: 2009-08-01 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -38,8 +38,12 @@ files:
38
38
  - README.rdoc
39
39
  - Rakefile
40
40
  - VERSION
41
+ - app/controllers/publications_controller.rb
42
+ - app/helpers/publications_helper.rb
43
+ - config/routes.rb
41
44
  - init.rb
42
45
  - lib/publishable.rb
46
+ - publishable.gemspec
43
47
  - test/rails_root/Rakefile
44
48
  - test/rails_root/app/controllers/application_controller.rb
45
49
  - test/rails_root/app/helpers/application_helper.rb
@@ -58,7 +62,6 @@ files:
58
62
  - test/rails_root/config/initializers/session_store.rb
59
63
  - test/rails_root/config/locales/en.yml
60
64
  - test/rails_root/config/routes.rb
61
- - test/rails_root/db/development.sqlite3
62
65
  - test/rails_root/db/migrate/20090731062231_create_posts.rb
63
66
  - test/rails_root/db/migrate/20090731073912_create_published_posts.rb
64
67
  - test/rails_root/db/schema.rb
@@ -84,8 +87,10 @@ files:
84
87
  - test/rails_root/script/plugin
85
88
  - test/rails_root/script/runner
86
89
  - test/rails_root/script/server
90
+ - test/rails_root/test/functional/publications_controller_test.rb
87
91
  - test/rails_root/test/performance/browsing_test.rb
88
92
  - test/rails_root/test/test_helper.rb
93
+ - test/rails_root/test/unit/helpers/publications_helper_test.rb
89
94
  - test/rails_root/test/unit/post_test.rb
90
95
  - test/rails_root/test/unit/published_post_test.rb
91
96
  has_rdoc: false
@@ -134,7 +139,9 @@ test_files:
134
139
  - test/rails_root/db/migrate/20090731062231_create_posts.rb
135
140
  - test/rails_root/db/migrate/20090731073912_create_published_posts.rb
136
141
  - test/rails_root/db/schema.rb
142
+ - test/rails_root/test/functional/publications_controller_test.rb
137
143
  - test/rails_root/test/performance/browsing_test.rb
138
144
  - test/rails_root/test/test_helper.rb
145
+ - test/rails_root/test/unit/helpers/publications_helper_test.rb
139
146
  - test/rails_root/test/unit/post_test.rb
140
147
  - test/rails_root/test/unit/published_post_test.rb
Binary file