paul_revere 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Appraisals CHANGED
@@ -1,4 +1,4 @@
1
- ['3.2.3', '3.1.4', '3.0.12'].each do |rails_version|
1
+ ['3.2.6', '3.1.6', '3.0.15'].each do |rails_version|
2
2
  appraise "rails-#{rails_version}" do
3
3
  gem "rails", rails_version
4
4
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paul_revere (1.0)
4
+ paul_revere (1.1)
5
5
  rails (~> 3.0)
6
6
 
7
7
  GEM
@@ -50,7 +50,7 @@ GEM
50
50
  i18n (>= 0.4.0)
51
51
  mime-types (~> 1.16)
52
52
  treetop (~> 1.4.8)
53
- mime-types (1.18)
53
+ mime-types (1.19)
54
54
  mocha (0.9.12)
55
55
  multi_json (1.0.3)
56
56
  polyglot (0.3.3)
data/NEWS.md CHANGED
@@ -1,3 +1,9 @@
1
+ New in 1.1:
2
+
3
+ * Support for the asset pipeline.
4
+ * More clear installation instructions for both newer and older Rails.
5
+ * The Announcement body is attr_accessible.
6
+
1
7
  New in 1.0:
2
8
 
3
9
  * Support for Rails 3.2.3, 3.1.4, and 3.0.12.
data/README.md CHANGED
@@ -6,17 +6,44 @@ Paul Revere
6
6
 
7
7
  Simple announcement plugin to include "one off" style announcements in Rails web apps.
8
8
 
9
- Install
10
- -------
9
+ Install with the asset pipeline (Rails 3.1+, asset pipeline enabled)
10
+ --------------------------------------------------------------------
11
11
 
12
12
  Install as normal in your Gemfile:
13
13
 
14
14
  gem 'paul_revere'
15
15
 
16
- Run the generator to create the migration and copy the javascript file into public:
16
+ Run the generator to create the migration:
17
17
 
18
18
  rails generate paul_revere
19
19
 
20
+ Add the announcement JS to `app/assets/javascripts/application.js`:
21
+
22
+ //= require announcements
23
+
24
+ Run the migration:
25
+
26
+ rake db:migrate && rake db:migrate:redo
27
+
28
+ Install without the asset pipeline (Rails 3.0 or asset pipeline disabled)
29
+ ---------------------------------------------------------------------------
30
+
31
+ Install as normal in your Gemfile:
32
+
33
+ gem 'paul_revere'
34
+
35
+ Run the generator to create the migration and copy the JavaScript file into public:
36
+
37
+ rails generate paul_revere
38
+
39
+ Add the announcement JS to your layout, such as `app/views/layouts/application.html.erb`:
40
+
41
+ <%= javascript_include_tag 'announcements' %>
42
+
43
+ Run the migration:
44
+
45
+ rake db:migrate && rake db:migrate:redo
46
+
20
47
  Usage
21
48
  -----
22
49
 
@@ -31,9 +58,13 @@ Paul Revere provides...
31
58
  So the flow would be...
32
59
 
33
60
  * Install the gem
34
- * Add `helper :announcements` either to application_controller.rb or to the specific controllers where you want to make the announcement helpers available
35
- * Use those partials in the correct places in your view code and mailer view code where you want announcements to show up
36
- * When you want to make an announcement, use the rails console to create a new Announcement record
61
+ * Use those partials in the correct places in your view code and mailer view code where you want announcements to show up:
62
+
63
+ <%= render 'announcements/announcement_for_all' %>
64
+
65
+ * When you want to make an announcement, use the Rails console to create a new `Announcement` record:
66
+
67
+ Announcement.create!(body: 'This Web site is shutting down because you refuse to pay')
37
68
 
38
69
  Beastie Boys Lyrics
39
70
  -------------------
@@ -104,7 +135,6 @@ His boy had beef and he got dropped
104
135
  Mike D. grabbed the money M.C.A. snatched the gold
105
136
  I grabbed two girlies and a beer that's cold.
106
137
 
107
-
108
138
  Credits
109
139
  -------
110
140
 
@@ -1,4 +1,6 @@
1
1
  class Announcement < ActiveRecord::Base
2
+ attr_accessible :body
3
+
2
4
  def self.current
3
5
  first(:order => 'created_at DESC') || new
4
6
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "3.0.12"
5
+ gem "rails", "3.0.15"
6
6
 
7
7
  gemspec :path=>"../"
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "3.2.3"
5
+ gem "rails", "3.1.6"
6
6
 
7
7
  gemspec :path=>"../"
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "3.1.4"
5
+ gem "rails", "3.2.6"
6
6
 
7
7
  gemspec :path=>"../"
@@ -4,11 +4,29 @@ class PaulRevereGenerator < Rails::Generators::Base
4
4
  include Rails::Generators::Migration
5
5
  extend ActiveRecord::Generators::Migration
6
6
 
7
- desc "Put the javascript and migration in place"
7
+ desc "Put the JavaScript and migration in place"
8
8
  source_root File.join(File.dirname(__FILE__), "templates")
9
9
 
10
10
  def install
11
- copy_file "announcements.js", "public/javascripts/announcements.js"
11
+ copy_javascript if needs_js_copied?
12
12
  migration_template "migration.rb", "db/migrate/create_announcements.rb"
13
13
  end
14
+
15
+ private
16
+
17
+ def copy_javascript
18
+ copy_file File.join(javascript_path, 'announcements.js'), js_destination
19
+ end
20
+
21
+ def javascript_path
22
+ File.join(%w(.. .. .. .. app assets javascripts))
23
+ end
24
+
25
+ def needs_js_copied?
26
+ ::Rails.version < '3.1' || !::Rails.application.config.assets.enabled
27
+ end
28
+
29
+ def js_destination
30
+ 'public/javascripts/announcements.js'
31
+ end
14
32
  end
@@ -1,3 +1,3 @@
1
1
  module PaulRevere
2
- VERSION = '1.0'.freeze
2
+ VERSION = '1.1'.freeze
3
3
  end
data/spec/fake_app.rb CHANGED
@@ -13,4 +13,8 @@ ActiveRecord::Base.establish_connection(
13
13
  :database => ":memory:"
14
14
  )
15
15
 
16
+ ActiveSupport.on_load(:active_record) do
17
+ attr_accessible(nil)
18
+ end
19
+
16
20
  CreateAnnouncements.suppress_messages { CreateAnnouncements.up }
@@ -4,19 +4,32 @@ require File.join(File.dirname(__FILE__), '..', '..', 'app', 'models', 'announce
4
4
 
5
5
  describe Announcement do
6
6
  it "should return the latest announcement when there are several" do
7
- old = Announcement.create!(:body => 'no fun', :created_at => 2.days.ago)
8
- latest = Announcement.create!(:body => 'fun', :created_at => 1.day.ago)
9
- older = Announcement.create!(:body => 'less fun', :created_at => 3.days.ago)
7
+ old = create_announcement(:body => 'no fun', :created_at => 2.days.ago)
8
+ latest = create_announcement(:body => 'fun', :created_at => 1.day.ago)
9
+ older = create_announcement(:body => 'less fun', :created_at => 3.days.ago)
10
10
 
11
11
  Announcement.current.should == latest
12
12
  end
13
13
 
14
14
  it "should return an existent announcement where there is no announcement" do
15
- Announcement.create!(:body => 'body')
15
+ create_announcement(:body => 'body')
16
16
  Announcement.current.exists?.should == true
17
17
  end
18
18
 
19
19
  it "should return a non-existent announcement where there is no announcement" do
20
20
  Announcement.current.exists?.should be_false
21
21
  end
22
+
23
+ it 'can always assign straight to the body' do
24
+ Announcement.create!(:body => 'hello').body.should == 'hello'
25
+ end
26
+
27
+ def create_announcement(attributes)
28
+ announcement = Announcement.new
29
+ attributes.each do |key, value|
30
+ announcement.send("#{key}=", value)
31
+ end
32
+ announcement.save!
33
+ announcement
34
+ end
22
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paul_revere
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -15,11 +15,11 @@ authors:
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2012-05-11 00:00:00.000000000Z
18
+ date: 2012-09-13 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rails
22
- requirement: &22372400 !ruby/object:Gem::Requirement
22
+ requirement: !ruby/object:Gem::Requirement
23
23
  none: false
24
24
  requirements:
25
25
  - - ~>
@@ -27,10 +27,15 @@ dependencies:
27
27
  version: '3.0'
28
28
  type: :runtime
29
29
  prerelease: false
30
- version_requirements: *22372400
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: '3.0'
31
36
  - !ruby/object:Gem::Dependency
32
37
  name: rspec
33
- requirement: &22371980 !ruby/object:Gem::Requirement
38
+ requirement: !ruby/object:Gem::Requirement
34
39
  none: false
35
40
  requirements:
36
41
  - - ! '>='
@@ -38,10 +43,15 @@ dependencies:
38
43
  version: '0'
39
44
  type: :development
40
45
  prerelease: false
41
- version_requirements: *22371980
46
+ version_requirements: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
42
52
  - !ruby/object:Gem::Dependency
43
53
  name: rspec-rails
44
- requirement: &22371520 !ruby/object:Gem::Requirement
54
+ requirement: !ruby/object:Gem::Requirement
45
55
  none: false
46
56
  requirements:
47
57
  - - ! '>='
@@ -49,10 +59,15 @@ dependencies:
49
59
  version: '0'
50
60
  type: :development
51
61
  prerelease: false
52
- version_requirements: *22371520
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
53
68
  - !ruby/object:Gem::Dependency
54
69
  name: sqlite3
55
- requirement: &22371100 !ruby/object:Gem::Requirement
70
+ requirement: !ruby/object:Gem::Requirement
56
71
  none: false
57
72
  requirements:
58
73
  - - ! '>='
@@ -60,10 +75,15 @@ dependencies:
60
75
  version: '0'
61
76
  type: :development
62
77
  prerelease: false
63
- version_requirements: *22371100
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
64
84
  - !ruby/object:Gem::Dependency
65
85
  name: mocha
66
- requirement: &22370680 !ruby/object:Gem::Requirement
86
+ requirement: !ruby/object:Gem::Requirement
67
87
  none: false
68
88
  requirements:
69
89
  - - ! '>='
@@ -71,10 +91,15 @@ dependencies:
71
91
  version: '0'
72
92
  type: :development
73
93
  prerelease: false
74
- version_requirements: *22370680
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
75
100
  - !ruby/object:Gem::Dependency
76
101
  name: appraisal
77
- requirement: &22370260 !ruby/object:Gem::Requirement
102
+ requirement: !ruby/object:Gem::Requirement
78
103
  none: false
79
104
  requirements:
80
105
  - - ! '>='
@@ -82,7 +107,12 @@ dependencies:
82
107
  version: '0'
83
108
  type: :development
84
109
  prerelease: false
85
- version_requirements: *22370260
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
86
116
  description: Paul Revere provides a model and helper methods to do one-off style announcements.
87
117
  email: support@thoughtbot.com
88
118
  executables: []
@@ -98,21 +128,18 @@ files:
98
128
  - NEWS.md
99
129
  - README.md
100
130
  - Rakefile
131
+ - app/assets/javascripts/announcements.js
101
132
  - app/helpers/announcements_helper.rb
102
133
  - app/models/announcement.rb
103
134
  - app/views/announcements/_announcement.html.erb
104
135
  - app/views/announcements/_announcement_for_all.html.erb
105
136
  - app/views/announcements/_email_announcement.erb
106
- - gemfiles/3.0.12.gemfile
107
- - gemfiles/3.1.4.gemfile
108
- - gemfiles/3.2.3.gemfile
109
- - gemfiles/rails-3.0.12.gemfile
110
- - gemfiles/rails-3.1.4.gemfile
111
- - gemfiles/rails-3.2.3.gemfile
137
+ - gemfiles/rails-3.0.15.gemfile
138
+ - gemfiles/rails-3.1.6.gemfile
139
+ - gemfiles/rails-3.2.6.gemfile
112
140
  - init.rb
113
141
  - lib/generators/paul_revere/USAGE
114
142
  - lib/generators/paul_revere/paul_revere_generator.rb
115
- - lib/generators/paul_revere/templates/announcements.js
116
143
  - lib/generators/paul_revere/templates/migration.rb
117
144
  - lib/paul_revere.rb
118
145
  - lib/paul_revere/version.rb
@@ -137,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
164
  version: '0'
138
165
  segments:
139
166
  - 0
140
- hash: -3043656868834385100
167
+ hash: -1368084792273439523
141
168
  required_rubygems_version: !ruby/object:Gem::Requirement
142
169
  none: false
143
170
  requirements:
@@ -146,10 +173,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
173
  version: '0'
147
174
  segments:
148
175
  - 0
149
- hash: -3043656868834385100
176
+ hash: -1368084792273439523
150
177
  requirements: []
151
178
  rubyforge_project:
152
- rubygems_version: 1.8.11
179
+ rubygems_version: 1.8.24
153
180
  signing_key:
154
181
  specification_version: 3
155
182
  summary: Simple announcement plugin to include 'one off' style announcements in Rails
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "3.1.4"
6
- gem "sass-rails"
7
- gem "coffee-script"
8
- gem "uglifier"
9
- gem "jquery-rails"
10
-
11
- gemspec :path=>"../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "3.2.3"
6
-
7
- gemspec :path=>"../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "rails", "3.0.12"
6
-
7
- gemspec :path=>"../"