exposure 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +41 -0
- data/README.mdown +39 -0
- data/Rakefile +26 -0
- data/exposure.gemspec +31 -0
- data/lib/exposure/common.rb +127 -0
- data/lib/exposure/configuration.rb +63 -0
- data/lib/exposure/patterns/resource.rb +226 -0
- data/lib/exposure/patterns/resources.rb +323 -0
- data/lib/exposure.rb +14 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/custom_matchers.rb +41 -0
- data/spec/exposure_spec.rb +4 -0
- data/spec/factories/pirate_factory.rb +8 -0
- data/spec/factories/ship_factory.rb +3 -0
- data/spec/finders/finder_spec.rb +53 -0
- data/spec/finders/nested_resources_finder_spec.rb +29 -0
- data/spec/fixtures/pirates/edit.erb +0 -0
- data/spec/fixtures/pirates/index.erb +0 -0
- data/spec/fixtures/pirates/new.erb +0 -0
- data/spec/fixtures/pirates/show.erb +0 -0
- data/spec/fixtures/ships/edit.erb +0 -0
- data/spec/fixtures/ships/index.erb +0 -0
- data/spec/fixtures/ships/new.erb +0 -0
- data/spec/fixtures/ships/show.erb +0 -0
- data/spec/flashers/flash_with_block_spec.rb +32 -0
- data/spec/flashers/flash_with_method_spec.rb +86 -0
- data/spec/flashers/flash_with_proc_spec.rb +83 -0
- data/spec/flashers/flash_with_string_spec.rb +82 -0
- data/spec/resource_spec.rb +192 -0
- data/spec/resources_spec.rb +204 -0
- data/spec/responders/respond_to_mime_types_spec.rb +44 -0
- data/spec/responders/respond_with_block_spec.rb +84 -0
- data/spec/responders/respond_with_method_spec.rb +84 -0
- data/spec/responders/respond_with_proc_spec.rb +79 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +71 -0
- data/spec/spec_rails_helper.rb +22 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/shoulda.rake +15 -0
- metadata +106 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "responders", :type => :controller do
|
4
|
+
class PiratesController < ActionController::Base
|
5
|
+
expose_many(:pirates)
|
6
|
+
|
7
|
+
private
|
8
|
+
def example
|
9
|
+
redirect_to({:action => "test"})
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
controller_name :pirates
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
@controller = PiratesController.new
|
17
|
+
@request = ActionController::TestRequest.new
|
18
|
+
@response = ActionController::TestResponse.new
|
19
|
+
ActionController::Routing::Routes.draw do |map|
|
20
|
+
map.resources :pirates, :collection => {:test => :any}
|
21
|
+
end
|
22
|
+
|
23
|
+
@pirate = Factory.stub(:pirate)
|
24
|
+
Pirate.stub(:new => @pirate)
|
25
|
+
end
|
26
|
+
|
27
|
+
after(:each) do
|
28
|
+
PiratesController::Responses.clear
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "responding with a method call" do
|
32
|
+
before(:each) do
|
33
|
+
PiratesController.response_for :create, :is => :example
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should respond with redirect to test on success" do
|
37
|
+
@pirate.stub(:save => true)
|
38
|
+
post(:create)
|
39
|
+
should redirect_to({:action => 'test'})
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should respond with redirect to test on failure" do
|
43
|
+
@pirate.stub(:save => false)
|
44
|
+
post(:create)
|
45
|
+
should redirect_to({:action => 'test'})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "responding with a method call :on => :success" do
|
50
|
+
before(:each) do
|
51
|
+
PiratesController.response_for :create, :is => :example, :on => :success
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should respond with custom response on success" do
|
55
|
+
@pirate.stub(:save => true)
|
56
|
+
post(:create)
|
57
|
+
should redirect_to({:action => 'test'})
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should not respond with custom response on failure" do
|
61
|
+
@pirate.stub(:save => false)
|
62
|
+
post(:create)
|
63
|
+
should_not redirect_to({:action => 'test'})
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "responding with a method call :on => :failure" do
|
68
|
+
before(:each) do
|
69
|
+
PiratesController.response_for :create, :is => :example, :on => :failure
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should not respond with custom response on success" do
|
73
|
+
@pirate.stub(:save => true)
|
74
|
+
post(:create)
|
75
|
+
should_not redirect_to({:action => 'test'})
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should respond with custom response on failure" do
|
79
|
+
@pirate.stub(:save => false)
|
80
|
+
post(:create)
|
81
|
+
should redirect_to({:action => 'test'})
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "responders", :type => :controller do
|
4
|
+
class PiratesController < ActionController::Base
|
5
|
+
expose_many(:pirates)
|
6
|
+
end
|
7
|
+
|
8
|
+
controller_name :pirates
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@controller = PiratesController.new
|
12
|
+
@request = ActionController::TestRequest.new
|
13
|
+
@response = ActionController::TestResponse.new
|
14
|
+
ActionController::Routing::Routes.draw do |map|
|
15
|
+
map.resources :pirates, :collection => {:test => :any}
|
16
|
+
end
|
17
|
+
@response_proc = Proc.new { redirect_to({:action => "test"}) }
|
18
|
+
@pirate = Factory.stub(:pirate)
|
19
|
+
Pirate.stub(:new => @pirate)
|
20
|
+
end
|
21
|
+
|
22
|
+
after(:each) do
|
23
|
+
PiratesController::Responses.clear
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "responding with a method call" do
|
27
|
+
before(:each) do
|
28
|
+
PiratesController.response_for :create, :is => @response_proc
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should respond with redirect to test on success" do
|
32
|
+
@pirate.stub(:save => true)
|
33
|
+
post(:create)
|
34
|
+
should redirect_to({:action => 'test'})
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should respond with redirect to test on failure" do
|
38
|
+
@pirate.stub(:save => false)
|
39
|
+
post(:create)
|
40
|
+
should redirect_to({:action => 'test'})
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "responding with a method call :on => :success" do
|
45
|
+
before(:each) do
|
46
|
+
PiratesController.response_for :create, :is => @response_proc, :on => :success
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should respond with custom response on success" do
|
50
|
+
@pirate.stub(:save => true)
|
51
|
+
post(:create)
|
52
|
+
should redirect_to({:action => 'test'})
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should not respond with custom response on failure" do
|
56
|
+
@pirate.stub(:save => false)
|
57
|
+
post(:create)
|
58
|
+
should_not redirect_to({:action => 'test'})
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "responding with a method call :on => :failure" do
|
63
|
+
before(:each) do
|
64
|
+
PiratesController.response_for :create, :is => @response_proc, :on => :failure
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should not respond with custom response on success" do
|
68
|
+
@pirate.stub(:save => true)
|
69
|
+
post(:create)
|
70
|
+
should_not redirect_to({:action => 'test'})
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should respond with custom response on failure" do
|
74
|
+
@pirate.stub(:save => false)
|
75
|
+
post(:create)
|
76
|
+
should redirect_to({:action => 'test'})
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
RAILS_ROOT = '.' unless defined? RAILS_ROOT
|
2
|
+
RAILS_ENV = 'test' unless defined? RAILS_ENV
|
3
|
+
|
4
|
+
module Rails
|
5
|
+
module VERSION
|
6
|
+
STRING = '2.3.4'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
require 'rubygems'
|
12
|
+
# require 'multi_rails_init'
|
13
|
+
|
14
|
+
require 'rubygems'
|
15
|
+
require 'action_controller'
|
16
|
+
require 'action_view'
|
17
|
+
require 'active_record'
|
18
|
+
require 'test_help'
|
19
|
+
|
20
|
+
require 'spec'
|
21
|
+
require File.dirname(__FILE__) + '/spec_rails_helper'
|
22
|
+
require 'shoulda'
|
23
|
+
require File.dirname(__FILE__) + "/custom_matchers"
|
24
|
+
require 'factory_girl'
|
25
|
+
|
26
|
+
|
27
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
28
|
+
require 'exposure'
|
29
|
+
|
30
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT) if ENV['DEBUG']
|
31
|
+
ActionController::Base.logger = Logger.new(STDOUT) if ENV['DEBUG']
|
32
|
+
ActionController::Base.send :include, Exposure
|
33
|
+
ActionController::Base.view_paths=(File.dirname(__FILE__) + '/fixtures')
|
34
|
+
|
35
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
36
|
+
ActiveRecord::Migration.verbose = false
|
37
|
+
|
38
|
+
ActiveRecord::Schema.define(:version => 1) do
|
39
|
+
create_table :pirates do |t|
|
40
|
+
t.column :title, :string
|
41
|
+
t.column :booty, :text
|
42
|
+
t.column :created_at, :datetime
|
43
|
+
t.column :updated_at, :datetime
|
44
|
+
end
|
45
|
+
create_table :ships do |t|
|
46
|
+
t.column :name, :string
|
47
|
+
t.column :pirate_id, :integer
|
48
|
+
t.column :created_at, :datetime
|
49
|
+
t.column :updated_at, :datetime
|
50
|
+
end
|
51
|
+
create_table :widgets do |t|
|
52
|
+
t.column :title, :string
|
53
|
+
t.column :body, :text
|
54
|
+
t.column :created_at, :datetime
|
55
|
+
t.column :updated_at, :datetime
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class Pirate < ActiveRecord::Base
|
60
|
+
has_many :ships
|
61
|
+
validates_length_of :title, :within => 2..100
|
62
|
+
def validate
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class Ship < ActiveRecord::Base
|
67
|
+
belongs_to :pirate
|
68
|
+
def validate
|
69
|
+
end
|
70
|
+
validates_associated :pirate
|
71
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# when spec/rails is required it expects to be inside a real Rails application and looks for
|
2
|
+
# classes and files that aren't present in the plugin. This is a copy of most of what is
|
3
|
+
# inside the spec-rails gem's initialization.
|
4
|
+
class ApplicationController
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rack/utils'
|
8
|
+
|
9
|
+
require 'action_controller/test_process'
|
10
|
+
require 'action_controller/integration'
|
11
|
+
require 'active_support/test_case'
|
12
|
+
require 'active_record/fixtures' if defined?(ActiveRecord::Base)
|
13
|
+
|
14
|
+
require 'spec/test/unit'
|
15
|
+
|
16
|
+
require 'spec/rails/matchers'
|
17
|
+
require 'spec/rails/mocks'
|
18
|
+
require 'spec/rails/example'
|
19
|
+
require 'spec/rails/extensions'
|
20
|
+
require 'spec/rails/interop/testcase'
|
21
|
+
|
22
|
+
Spec::Example::ExampleGroupFactory.default(ActiveSupport::TestCase)
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|
data/tasks/shoulda.rake
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
begin
|
2
|
+
require 'shoulda'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
5
|
+
require 'shoulda'
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'rake/testtask'
|
9
|
+
|
10
|
+
desc "Run the shoulda test under /spec"
|
11
|
+
Rake::TestTask.new do |t|
|
12
|
+
t.libs << "test"
|
13
|
+
t.test_files = FileList['spec/*_spec.rb']
|
14
|
+
t.verbose = true
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: exposure
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Trek Glowacki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-07 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.3.3
|
24
|
+
version:
|
25
|
+
description: Expose your data
|
26
|
+
email:
|
27
|
+
- trek.glowacki@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- Manifest.txt
|
34
|
+
files:
|
35
|
+
- Manifest.txt
|
36
|
+
- README.mdown
|
37
|
+
- Rakefile
|
38
|
+
- exposure.gemspec
|
39
|
+
- lib/exposure.rb
|
40
|
+
- lib/exposure/common.rb
|
41
|
+
- lib/exposure/configuration.rb
|
42
|
+
- lib/exposure/patterns/resource.rb
|
43
|
+
- lib/exposure/patterns/resources.rb
|
44
|
+
- script/console
|
45
|
+
- script/destroy
|
46
|
+
- script/generate
|
47
|
+
- spec/custom_matchers.rb
|
48
|
+
- spec/exposure_spec.rb
|
49
|
+
- spec/factories/pirate_factory.rb
|
50
|
+
- spec/factories/ship_factory.rb
|
51
|
+
- spec/finders/finder_spec.rb
|
52
|
+
- spec/finders/nested_resources_finder_spec.rb
|
53
|
+
- spec/fixtures/pirates/edit.erb
|
54
|
+
- spec/fixtures/pirates/index.erb
|
55
|
+
- spec/fixtures/pirates/new.erb
|
56
|
+
- spec/fixtures/pirates/show.erb
|
57
|
+
- spec/fixtures/ships/edit.erb
|
58
|
+
- spec/fixtures/ships/index.erb
|
59
|
+
- spec/fixtures/ships/new.erb
|
60
|
+
- spec/fixtures/ships/show.erb
|
61
|
+
- spec/flashers/flash_with_block_spec.rb
|
62
|
+
- spec/flashers/flash_with_method_spec.rb
|
63
|
+
- spec/flashers/flash_with_proc_spec.rb
|
64
|
+
- spec/flashers/flash_with_string_spec.rb
|
65
|
+
- spec/resource_spec.rb
|
66
|
+
- spec/resources_spec.rb
|
67
|
+
- spec/responders/respond_to_mime_types_spec.rb
|
68
|
+
- spec/responders/respond_with_block_spec.rb
|
69
|
+
- spec/responders/respond_with_method_spec.rb
|
70
|
+
- spec/responders/respond_with_proc_spec.rb
|
71
|
+
- spec/spec.opts
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
- spec/spec_rails_helper.rb
|
74
|
+
- tasks/rspec.rake
|
75
|
+
- tasks/shoulda.rake
|
76
|
+
has_rdoc: true
|
77
|
+
homepage:
|
78
|
+
licenses: []
|
79
|
+
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options:
|
82
|
+
- --main
|
83
|
+
- README.rdoc
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0"
|
91
|
+
version:
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: "0"
|
97
|
+
version:
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.3.4
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: Expose your data
|
105
|
+
test_files: []
|
106
|
+
|