simply_messages 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,4 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ log/*
5
6
  *.swp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = simply_messages
2
2
 
3
- simply_messages is a Rails plugin providing a unified notice/alert messages handling (like those: flash.now[:notice] = 'Yeah').
3
+ simply_messages is a Rails plugin providing a unified notice/alert messages handling (like those: flash.now[:notice] = 'Yeah') and model validation errors.
4
4
  Based on the message_block by Ben Hughes (http://github.com/railsgarden/message_block).
5
5
 
6
6
 
@@ -37,7 +37,7 @@ In `app/views/layouts/application.html.erb`:
37
37
  <%= messages_block %>
38
38
 
39
39
 
40
- By default the messages_block function will display all flash[:notice] and flash[:alert] messages and all errors for model object associated by name with the current controller (so it will display all model errors for @user model when 'users' is the current controller). Will also display appropriate messages for :success and :error flash keys.
40
+ By default the messages_block function will display all flash[:notice] and flash[:alert] messages and all errors for model object associated by name with the current controller (so it will display all model errors for @user model when 'users' is the current controller). It will also display appropriate messages for :success and :error flash keys.
41
41
 
42
42
  We can also explicitly set the model we would like to display errors for, like this:
43
43
 
@@ -72,11 +72,11 @@ Given a User model instance with one validation error:
72
72
  user.errors
73
73
  => #<OrderedHash {:name=>["can't be blank"]}>
74
74
 
75
- and this in view in the users controller:
75
+ and this in the view in the users controller:
76
76
 
77
77
  <%= messages_block %>
78
78
 
79
- will render:
79
+ it will render:
80
80
 
81
81
  <div class="alert">
82
82
  <p>1 error prohibited this User from being saved:</p>
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ end
11
11
 
12
12
  task :default => :spec
13
13
 
14
- require 'rake/rdoctask'
14
+ require 'rdoc/task'
15
15
  Rake::RDocTask.new do |rdoc|
16
16
  require 'simply_messages/version'
17
17
  rdoc.rdoc_dir = 'rdoc'
@@ -1,3 +1,3 @@
1
1
  module SimplyMessages
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.summary = 'Unified flash notices and model error messages display solution'
14
14
  s.description = 'simply_messages is a unified flash and error messages display solution'
15
15
 
16
- s.rubyforge_project = 'simply_messages'
16
+ s.rubyforge_project = 'simply-messages'
17
17
 
18
18
  s.files = `git ls-files`.split("\n")
19
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
data/spec/app.rb ADDED
@@ -0,0 +1,59 @@
1
+ require 'active_record'
2
+ require 'action_controller/railtie'
3
+ require 'action_view/railtie'
4
+
5
+ # database
6
+ ActiveRecord::Base.configurations = { 'test' => { :adapter => 'sqlite3', :database => ':memory:' } }
7
+ ActiveRecord::Base.establish_connection 'test'
8
+
9
+ # config
10
+ app = Class.new(Rails::Application)
11
+ app.config.secret_token = "2jv9wver8j3haskhf23b4j51ho8f8vh1"
12
+ app.config.session_store :cookie_store, :key => "_simply_messages_session"
13
+ app.config.active_support.deprecation = :log
14
+ app.initialize!
15
+
16
+ # route
17
+ app.routes.draw do
18
+ resources :users, :only => [:index, :create]
19
+ end
20
+
21
+ # model
22
+ class User < ActiveRecord::Base
23
+ validates_presence_of :name, :age
24
+ end
25
+
26
+ # controllers
27
+ class ApplicationController < ActionController::Base
28
+ end
29
+
30
+ class UsersController < ApplicationController
31
+ def index
32
+ flash.now[:notice] = 'Good'
33
+ flash.now[:success] = 'Good'
34
+ flash.now[:alert] = 'Not too good'
35
+ render :inline => "<%= messages_block %>"
36
+ end
37
+
38
+ def create
39
+ @user = User.create(params[:user])
40
+ render :inline => "<%= messages_block %>"
41
+ end
42
+ end
43
+
44
+ # helpers
45
+ Object.const_set(:ApplicationHelper, Module.new)
46
+
47
+ # migration
48
+ class CreateUsers < ActiveRecord::Migration
49
+ def self.up
50
+ create_table(:users) do |t|
51
+ t.string :name, :null => false
52
+ t.integer :age, :null => false
53
+ end
54
+ end
55
+ end
56
+
57
+ # I18n
58
+ I18n.backend.store_translations :en, :activerecord => { :errors => { :template => { :header => { :one => 'There is one error' } } } }
59
+ I18n.backend.store_translations :en, :activerecord => { :errors => { :template => { :header => { :other => 'There are %{count} errors' } } } }
@@ -0,0 +1,44 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe UsersController do
4
+
5
+ render_views
6
+
7
+ describe "#index" do
8
+ before do
9
+ get :index
10
+ end
11
+
12
+ specify { response.should be_success }
13
+
14
+ specify { response.should have_selector('div.notice p', :content => 'Good') }
15
+ specify { response.should have_selector('div.success p', :content => 'Good') }
16
+ specify { response.should have_selector('div.alert p', :content => 'Not too good') }
17
+ end
18
+
19
+ describe "#create" do
20
+ context "without name" do
21
+ before do
22
+ post :create, :user => { :age => 21 }
23
+ end
24
+
25
+ specify { response.should be_success }
26
+
27
+ specify { response.should have_selector('div.alert p', :content => "error") }
28
+ specify { response.should have_selector('div.alert li', :content => "Name can't be blank") }
29
+ end
30
+
31
+ context "without name and age" do
32
+ before do
33
+ post :create
34
+ end
35
+
36
+ specify { response.should be_success }
37
+
38
+ specify { response.should have_selector('div.alert p', :content => "error") }
39
+ specify { response.should have_selector('div.alert li', :content => "Name can't be blank") }
40
+ specify { response.should have_selector('div.alert li', :content => "Age can't be blank") }
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,28 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $:.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rails'
5
+ require 'simply_messages'
6
+
7
+ require File.join(File.dirname(__FILE__), 'app')
8
+
9
+ require 'rspec/rails'
10
+
11
+ # Requires supporting ruby files with custom matchers and macros, etc.
12
+ # in spec/support/ and its subdirectories.
13
+ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
14
+
15
+ require "webrat"
16
+
17
+ Webrat.configure do |config|
18
+ config.mode = :rails
19
+ end
20
+
21
+ RSpec.configure do |config|
22
+ config.mock_with :rspec
23
+
24
+ # run migrations
25
+ config.before :all do
26
+ CreateUsers.up unless ActiveRecord::Base.connection.table_exists? 'users'
27
+ end
28
+ end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Pawe\xC5\x82 Go\xC5\x9Bcicki"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-15 00:00:00 +02:00
18
+ date: 2011-05-20 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -117,6 +117,7 @@ extra_rdoc_files:
117
117
  - README.rdoc
118
118
  files:
119
119
  - .gitignore
120
+ - .rspec
120
121
  - Gemfile
121
122
  - MIT-LICENSE
122
123
  - README.rdoc
@@ -126,8 +127,9 @@ files:
126
127
  - lib/simply_messages/railtie.rb
127
128
  - lib/simply_messages/version.rb
128
129
  - simply_messages.gemspec
129
- - test/functional/helpers_test.rb
130
- - test/test_helper.rb
130
+ - spec/app.rb
131
+ - spec/controllers/users_controller_spec.rb
132
+ - spec/spec_helper.rb
131
133
  has_rdoc: true
132
134
  homepage: https://github.com/pjg/simply_messages
133
135
  licenses:
@@ -157,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
159
  version: "0"
158
160
  requirements: []
159
161
 
160
- rubyforge_project: simply_messages
162
+ rubyforge_project: simply-messages
161
163
  rubygems_version: 1.6.2
162
164
  signing_key:
163
165
  specification_version: 3
@@ -1,81 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
- require 'action_controller'
3
- require 'action_controller/test_process'
4
-
5
- class Mock
6
- attr_accessor :errors
7
-
8
- def initialize(opts = {})
9
- # create Errors object so I could add errors to this mock model
10
- @errors = ActiveRecord::Errors.new(self)
11
- end
12
- end
13
-
14
- class MocksController < ApplicationController
15
- def success
16
- flash.now[:success] = 'We have a success'
17
- render :inline => '<%= messages_block %>'
18
- end
19
-
20
- def notice
21
- flash.now[:notice] = 'We have a notice'
22
- render :inline => '<%= messages_block %>'
23
- end
24
-
25
- def error
26
- flash.now[:error] = 'Error: no luck this time'
27
- render :inline => '<%= messages_block %>'
28
- end
29
-
30
- def alert
31
- flash.now[:alert] = 'Alert: no luck this time'
32
- render :inline => '<%= messages_block %>'
33
- end
34
-
35
- def model_error
36
- flash.now[:error] = 'Model error'
37
- @mock = Mock.new
38
- @mock.errors.add('name', 'just having some troubles')
39
- render :inline => '<%= messages_block %>'
40
- end
41
- end
42
-
43
- class MocksControllerTest < ActionController::TestCase
44
-
45
- def setup
46
- @controller = MocksController.new
47
- @request = ActionController::TestRequest.new
48
- @response = ActionController::TestResponse.new
49
-
50
- ActionController::Routing::Routes.draw do |map|
51
- map.connect ':controller/:action/:id'
52
- end
53
- end
54
-
55
- def test_success
56
- get :success
57
- assert_select 'div.success p', :text => /We have a success./
58
- end
59
-
60
- def test_notice
61
- get :notice
62
- assert_select 'div.notice p', :text => /We have a notice./
63
- end
64
-
65
- def test_error
66
- get :error
67
- assert_select 'div.error p', :text => /Error: no luck this time./
68
- end
69
-
70
- def test_alert
71
- get :alert
72
- assert_select 'div.alert p', :text => /Alert: no luck this time./
73
- end
74
-
75
- def test_model_error
76
- get :model_error
77
- assert_select 'div.error p', :text => /Model error:/
78
- assert_select 'div.error ul li', :text => /just having some troubles/
79
- end
80
-
81
- end
data/test/test_helper.rb DELETED
@@ -1,11 +0,0 @@
1
- ENV['RAILS_ENV'] = 'test'
2
- ENV['RAILS_ROOT'] ||= File.dirname(__FILE__) + '/../../../..'
3
-
4
- # Optional gems
5
- begin
6
- require 'redgreen'
7
- rescue LoadError
8
- end
9
-
10
- # Load Rails
11
- require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config/environment.rb'))