governor 0.2.3 → 0.3.0

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ./
3
3
  specs:
4
- governor (0.2.2)
4
+ governor (0.3.0)
5
5
  rails (~> 3.0.5)
6
6
 
7
7
  GEM
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.3.0
@@ -7,38 +7,34 @@ class Governor::ArticlesController < ApplicationController
7
7
 
8
8
  helper Governor::Controllers::Helpers
9
9
 
10
+ respond_to :html
11
+ Governor::PluginManager.plugins.each do |plugin|
12
+ plugin.mimes.each{|mimes| respond_to *mimes.dup }
13
+ end
14
+
10
15
  # GET /articles
11
16
  # GET /articles.xml
12
17
  def index
13
18
  set_resources model_class.paginate :page => params[:page], :order => 'created_at DESC'
14
- respond_to do |format|
15
- format.html # index.html.erb
16
- format.xml { render :xml => resources }
17
- end
19
+ respond_with resources
18
20
  end
19
21
 
20
22
  # GET /articles/1
21
23
  # GET /articles/1.xml
22
24
  def show
23
- respond_to do |format|
24
- format.html # show.html.erb
25
- format.xml { render :xml => resource }
26
- end
25
+ respond_with resource
27
26
  end
28
27
 
29
28
  # GET /articles/new
30
29
  # GET /articles/new.xml
31
30
  def new
32
31
  set_resource model_class.new
33
-
34
- respond_to do |format|
35
- format.html # new.html.erb
36
- format.xml { render :xml => resource }
37
- end
32
+ respond_with resource
38
33
  end
39
34
 
40
35
  # GET /articles/1/edit
41
36
  def edit
37
+ respond_with resource
42
38
  end
43
39
 
44
40
  # POST /articles
@@ -46,43 +42,27 @@ class Governor::ArticlesController < ApplicationController
46
42
  def create
47
43
  set_resource model_class.new(params[mapping.singular])
48
44
  resource.author = the_governor
49
-
50
- respond_to do |format|
51
- if resource.save
52
- flash[:notice] = "#{mapping.humanize} was successfully created."
53
- format.html { redirect_to(resource) }
54
- format.xml { render :xml => resource, :status => :created, :location => resource }
55
- else
56
- format.html { render :action => 'new' }
57
- format.xml { render :xml => resource.errors, :status => :unprocessable_entity }
58
- end
45
+ if resource.save
46
+ flash[:notice] = "#{mapping.humanize} was successfully created."
59
47
  end
48
+ respond_with resource
60
49
  end
61
50
 
62
51
  # PUT /articles/1
63
52
  # PUT /articles/1.xml
64
53
  def update
65
- respond_to do |format|
66
- if resource.update_attributes(params[mapping.singular])
67
- flash[:notice] = "#{mapping.humanize} was successfully updated."
68
- format.html { redirect_to(resource) }
69
- format.xml { head :ok }
70
- else
71
- format.html { render :action => 'edit' }
72
- format.xml { render :xml => resource.errors, :status => :unprocessable_entity }
73
- end
54
+ if resource.update_attributes(params[mapping.singular])
55
+ flash[:notice] = "#{mapping.humanize} was successfully updated."
74
56
  end
57
+ respond_with resource
75
58
  end
76
59
 
77
60
  # DELETE /articles/1
78
61
  # DELETE /articles/1.xml
79
62
  def destroy
80
63
  resource.destroy
81
-
82
- respond_to do |format|
83
- format.html { redirect_to(polymorphic_path(mapping.plural)) }
84
- format.xml { head :ok }
85
- end
64
+ flash[:notice] = "#{mapping.humanize} was successfully updated."
65
+ respond_with resource
86
66
  end
87
67
 
88
68
  def find_by_date
@@ -13,7 +13,7 @@
13
13
 
14
14
  <p id="article_text">
15
15
  <b><%= f.label :post %></b><br>
16
- <%= f.text_area :post %>
16
+ <%= f.text_area :post -%>
17
17
  </p>
18
18
 
19
19
  <p>
@@ -0,0 +1,26 @@
1
+ = error_messages_for resource_sym
2
+
3
+ = form_for resource do |f|
4
+ %p
5
+ %b= f.label :title
6
+ %br
7
+ = f.text_field :title
8
+
9
+ %p
10
+ %b= f.label :description
11
+ %br
12
+ = f.text_field :description
13
+
14
+ %p#article_text
15
+ %b= f.label :post
16
+ %br
17
+ ~ f.text_area :post
18
+
19
+ %p
20
+ %b= f.label :format
21
+ = f.select :format, Governor::Formatters.available_formatters.keys
22
+
23
+ = render_plugin_partial('bottom_of_form', :locals => {:f => f})
24
+
25
+ %p
26
+ = f.submit "#{controller.action_name.titleize} Article"
data/governor.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{governor}
8
- s.version = "0.2.3"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Liam Morley"]
12
- s.date = %q{2011-04-12}
12
+ s.date = %q{2011-04-16}
13
13
  s.description = %q{Because Blogojevich would be too tough to remember. It's a pluggable blogging system for Rails 3.}
14
14
  s.email = %q{liam@carpeliam.com}
15
15
  s.extra_rdoc_files = [
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "app/helpers/governor_helper.rb",
30
30
  "app/views/governor/articles/_article.html.erb",
31
31
  "app/views/governor/articles/_form.html.erb",
32
+ "app/views/governor/articles/_form.html.haml",
32
33
  "app/views/governor/articles/edit.html.erb",
33
34
  "app/views/governor/articles/index.html.erb",
34
35
  "app/views/governor/articles/new.html.erb",
@@ -71,6 +72,7 @@ Gem::Specification.new do |s|
71
72
  "spec/rails_app/app/helpers/home_helper.rb",
72
73
  "spec/rails_app/app/models/article.rb",
73
74
  "spec/rails_app/app/models/user.rb",
75
+ "spec/rails_app/app/views/governor/articles/index.xml.builder",
74
76
  "spec/rails_app/app/views/home/index.html.erb",
75
77
  "spec/rails_app/app/views/layouts/application.html.erb",
76
78
  "spec/rails_app/config.ru",
@@ -84,6 +86,7 @@ Gem::Specification.new do |s|
84
86
  "spec/rails_app/config/initializers/backtrace_silencers.rb",
85
87
  "spec/rails_app/config/initializers/devise.rb",
86
88
  "spec/rails_app/config/initializers/governor.rb",
89
+ "spec/rails_app/config/initializers/governor_testing.rb",
87
90
  "spec/rails_app/config/initializers/inflections.rb",
88
91
  "spec/rails_app/config/initializers/mime_types.rb",
89
92
  "spec/rails_app/config/initializers/secret_token.rb",
@@ -141,6 +144,7 @@ Gem::Specification.new do |s|
141
144
  "spec/rails_app/config/initializers/backtrace_silencers.rb",
142
145
  "spec/rails_app/config/initializers/devise.rb",
143
146
  "spec/rails_app/config/initializers/governor.rb",
147
+ "spec/rails_app/config/initializers/governor_testing.rb",
144
148
  "spec/rails_app/config/initializers/inflections.rb",
145
149
  "spec/rails_app/config/initializers/mime_types.rb",
146
150
  "spec/rails_app/config/initializers/secret_token.rb",
@@ -1,12 +1,13 @@
1
1
  module Governor
2
2
  class Plugin
3
- attr_reader :name, :migrations, :routes, :resources, :helpers
3
+ attr_reader :name, :migrations, :routes, :resources, :helpers, :mimes
4
4
  def initialize(name)
5
5
  @name = name
6
6
  @migrations = []
7
7
  @helpers = []
8
8
  @resources = {}
9
9
  @partials = {}
10
+ @mimes = []
10
11
  end
11
12
 
12
13
  def add_migration(path)
@@ -86,5 +87,9 @@ module Governor
86
87
  def register_model_callback(&block)
87
88
  @model_callback = block
88
89
  end
90
+
91
+ def responds_to(*mimes)
92
+ @mimes << mimes
93
+ end
89
94
  end
90
95
  end
@@ -20,7 +20,7 @@ module ActionDispatch #:nodoc:
20
20
  mapping = Governor.map(resource, options)
21
21
  resources mapping.resource, :controller => mapping.controller, :governor_mapping => resource do
22
22
  Governor::PluginManager.plugins.map{|p| p.routes }.each do |routes|
23
- instance_eval(&routes)
23
+ instance_eval(&routes) if routes.present?
24
24
  end
25
25
  end
26
26
  end
@@ -12,7 +12,7 @@ module ActionDispatch::Routing
12
12
  end
13
13
  Governor::PluginManager.register @plugin
14
14
 
15
- @article = Factory(:article)
15
+ @article = Factory(:article, :author => Factory(:user))
16
16
  Rails.application.reload_routes!
17
17
  end
18
18
 
@@ -4,6 +4,37 @@ module Governor
4
4
  describe ArticlesController do
5
5
  include Devise::TestHelpers
6
6
 
7
+ context "which has a plugin with a registered mime response" do
8
+ # not sure how to add something before the controller is loaded, so I
9
+ # added an initializer which adds a plugin that registers a type. See
10
+ # 'governor_testing' in the rails_app/config/initializers directory:
11
+ #
12
+ # plugin = Governor::Plugin.new('xml support')
13
+ # plugin.responds_to :xml, :only => [:index]
14
+ # Governor::PluginManager.register plugin
15
+ #
16
+ render_views
17
+ it "responds to standard html" do
18
+ get :index, :governor_mapping => :articles
19
+ assigns[:articles].should == [@article]
20
+ response.status.should == 200 # :success
21
+ end
22
+ it "doesn't respond to JSON" do
23
+ get :index, :governor_mapping => :articles, :format => :json
24
+ response.status.should == 406 # :not_acceptable
25
+ end
26
+ it "responds to index.xml because the plugin added it" do
27
+ get :index, :governor_mapping => :articles, :format => :xml
28
+ assigns[:articles].should == [@article]
29
+ response.status.should == 200 # :success
30
+ response.body.should =~ /It worked/
31
+ end
32
+ it "doesn't respond to show.xml" do
33
+ get :show, :governor_mapping => :articles, :id => @article.id, :format => :xml
34
+ response.status.should == 406 # :not_acceptable
35
+ end
36
+ end
37
+
7
38
  before(:each) do
8
39
  @user = Factory(:user)
9
40
  @article = Factory(:article, :author => @user)
@@ -73,7 +104,7 @@ module Governor
73
104
  context "when signed in" do
74
105
  before(:each) { sign_in @user }
75
106
  it "creates a new article and redirects to its page" do
76
- post :create, :governor_mapping => :articles
107
+ post :create, :governor_mapping => :articles, :article => {:title => 'Want a job?', :post => 'I accept checks'}
77
108
  assigns[:article].should be_a ::Article
78
109
  assigns[:article].should_not be_a_new_record
79
110
  assigns[:article].author.should == @user
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- governor (0.1.1)
4
+ governor (0.3.0)
5
5
  rails (~> 3.0.5)
6
6
 
7
7
  GEM
@@ -0,0 +1,5 @@
1
+ xml.instruct!
2
+ xml.success do
3
+ xml.message "It worked."
4
+ xml.test_description "This is a test to make sure that other plugins can register to listen for mime types"
5
+ end
@@ -0,0 +1,4 @@
1
+ # For testing purposes:
2
+ plugin = Governor::Plugin.new('xml support')
3
+ plugin.responds_to :xml, :only => [:index]
4
+ Governor::PluginManager.register plugin
@@ -1,6 +1,7 @@
1
1
  FactoryGirl.define do
2
2
  factory :article do |a|
3
3
  a.title "Some article"
4
+ a.post "This is the post. It shouldn't be blank."
4
5
  end
5
6
 
6
7
  factory :user do |u|
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: governor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
8
  - 3
10
- version: 0.2.3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Liam Morley
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-12 00:00:00 -04:00
18
+ date: 2011-04-16 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -219,6 +219,7 @@ files:
219
219
  - app/helpers/governor_helper.rb
220
220
  - app/views/governor/articles/_article.html.erb
221
221
  - app/views/governor/articles/_form.html.erb
222
+ - app/views/governor/articles/_form.html.haml
222
223
  - app/views/governor/articles/edit.html.erb
223
224
  - app/views/governor/articles/index.html.erb
224
225
  - app/views/governor/articles/new.html.erb
@@ -261,6 +262,7 @@ files:
261
262
  - spec/rails_app/app/helpers/home_helper.rb
262
263
  - spec/rails_app/app/models/article.rb
263
264
  - spec/rails_app/app/models/user.rb
265
+ - spec/rails_app/app/views/governor/articles/index.xml.builder
264
266
  - spec/rails_app/app/views/home/index.html.erb
265
267
  - spec/rails_app/app/views/layouts/application.html.erb
266
268
  - spec/rails_app/config.ru
@@ -274,6 +276,7 @@ files:
274
276
  - spec/rails_app/config/initializers/backtrace_silencers.rb
275
277
  - spec/rails_app/config/initializers/devise.rb
276
278
  - spec/rails_app/config/initializers/governor.rb
279
+ - spec/rails_app/config/initializers/governor_testing.rb
277
280
  - spec/rails_app/config/initializers/inflections.rb
278
281
  - spec/rails_app/config/initializers/mime_types.rb
279
282
  - spec/rails_app/config/initializers/secret_token.rb
@@ -359,6 +362,7 @@ test_files:
359
362
  - spec/rails_app/config/initializers/backtrace_silencers.rb
360
363
  - spec/rails_app/config/initializers/devise.rb
361
364
  - spec/rails_app/config/initializers/governor.rb
365
+ - spec/rails_app/config/initializers/governor_testing.rb
362
366
  - spec/rails_app/config/initializers/inflections.rb
363
367
  - spec/rails_app/config/initializers/mime_types.rb
364
368
  - spec/rails_app/config/initializers/secret_token.rb