controller_resources 0.0.6 → 0.1.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.
@@ -1,29 +1,13 @@
1
- <%= form_for(@post) do |f| %>
2
- <% if @post.errors.any? %>
3
- <div id="error_explanation">
4
- <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
5
-
6
- <ul>
7
- <% @post.errors.full_messages.each do |message| %>
8
- <li><%= message %></li>
9
- <% end %>
10
- </ul>
11
- </div>
12
- <% end %>
13
-
1
+ <%= form_for(post) do |f| %>
14
2
  <div class="field">
15
- <%= f.label :title %><br>
3
+ <%= f.label :title, 'Title' %><br>
16
4
  <%= f.text_field :title %>
17
5
  </div>
18
6
  <div class="field">
19
- <%= f.label :body %><br>
7
+ <%= f.label :body, 'Body' %><br>
20
8
  <%= f.text_field :body %>
21
9
  </div>
22
- <div class="field">
23
- <%= f.label :is_published %><br>
24
- <%= f.check_box :is_published %>
25
- </div>
26
10
  <div class="actions">
27
- <%= f.submit %>
11
+ <%= f.submit 'Save' %>
28
12
  </div>
29
13
  <% end %>
@@ -2,5 +2,5 @@
2
2
 
3
3
  <%= render 'form' %>
4
4
 
5
- <%= link_to 'Show', @post %> |
5
+ <%= link_to 'Show', post %> |
6
6
  <%= link_to 'Back', posts_path %>
@@ -7,17 +7,15 @@
7
7
  <tr>
8
8
  <th>Title</th>
9
9
  <th>Body</th>
10
- <th>Is published</th>
11
10
  <th colspan="3"></th>
12
11
  </tr>
13
12
  </thead>
14
13
 
15
14
  <tbody>
16
- <% @posts.each do |post| %>
15
+ <% posts.each do |post| %>
17
16
  <tr>
18
17
  <td><%= post.title %></td>
19
18
  <td><%= post.body %></td>
20
- <td><%= post.is_published %></td>
21
19
  <td><%= link_to 'Show', post %></td>
22
20
  <td><%= link_to 'Edit', edit_post_path(post) %></td>
23
21
  <td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td>
@@ -2,18 +2,13 @@
2
2
 
3
3
  <p>
4
4
  <strong>Title:</strong>
5
- <%= @post.title %>
5
+ <%= post.title %>
6
6
  </p>
7
7
 
8
8
  <p>
9
9
  <strong>Body:</strong>
10
- <%= @post.body %>
10
+ <%= post.body %>
11
11
  </p>
12
12
 
13
- <p>
14
- <strong>Is published:</strong>
15
- <%= @post.is_published %>
16
- </p>
17
-
18
- <%= link_to 'Edit', edit_post_path(@post) %> |
13
+ <%= link_to 'Edit', edit_post_path(post) %> |
19
14
  <%= link_to 'Back', posts_path %>
@@ -1,15 +1,3 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Your secret key is used for verifying the integrity of signed cookies.
4
- # If you change this key, all old signed cookies will become invalid!
5
-
6
- # Make sure the secret is at least 30 characters and all random,
7
- # no regular words or you'll be exposed to dictionary attacks.
8
- # You can use `rake secret` to generate a secure secret key.
9
-
10
- # Make sure the secrets in this file are kept private
11
- # if you're sharing your code publicly.
12
-
13
1
  development:
14
2
  secret_key_base: ee235ede341b4f697df9ef05ff28428e298b95d4fbad4c4959d792ca892f3af362cc2a5d53e8a688c892a6add3a7602685745053ab190ee3da153c3d6db51a71
15
3
 
@@ -0,0 +1,2 @@
1
+ puts 'creating post record'
2
+ Post.create title: 'title', body: 'body'
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.feature 'posts' do
4
+ let :post do
5
+ Post.all.first
6
+ end
7
+
8
+ scenario 'listing all posts' do
9
+ visit posts_path
10
+
11
+ expect(page).to have_content 'Posts'
12
+ expect(page).to have_content post.title
13
+ end
14
+
15
+ scenario 'showing a single post' do
16
+ visit post_path(post)
17
+
18
+ expect(page).to have_content post.title
19
+ expect(page).to have_content post.body
20
+ end
21
+
22
+ scenario 'creating a new post' do
23
+ skip
24
+ visit new_post_path
25
+
26
+ fill_in 'post[title]', with: 'new post'
27
+ fill_in 'post[body]', with: 'this is a new post'
28
+ click_button 'Save'
29
+
30
+ expect(page).to have_content 'Listing Posts'
31
+ end
32
+
33
+ scenario 'editing an existing post' do
34
+ skip
35
+ visit edit_post_path(post)
36
+
37
+ fill_in 'post[title]', with: 'new title'
38
+ click_button 'Save'
39
+
40
+ expect(page).to have_content 'new title'
41
+ end
42
+
43
+ scenario 'deleting an existing post' do
44
+ visit posts_path(post, method: :delete)
45
+
46
+ expect(page).to have_content 'Listing Posts'
47
+ end
48
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ControllerResources, type: :lib do
4
+ subject do
5
+ TestController.new
6
+ end
7
+
8
+ before do
9
+ subject.class_eval do
10
+ include ControllerResources
11
+
12
+ resource :post do
13
+ permit :title
14
+ end
15
+ end
16
+
17
+ allow(subject).to receive(:params).and_return(
18
+ double('Parameters', require: double('Required', permit: true))
19
+ )
20
+ end
21
+
22
+ it 'defines model_name' do
23
+ expect(subject.model_name).to eq :post
24
+ end
25
+
26
+ it 'defines collection_name' do
27
+ expect(subject.collection_name).to eq :posts
28
+ end
29
+
30
+ it 'computes model from model_name' do
31
+ expect(subject).to respond_to :model
32
+ expect(subject.post).to eq subject.model
33
+ end
34
+
35
+ it 'computes collection from collection_name' do
36
+ expect(subject).to respond_to :collection
37
+ expect(subject.collection).to include(subject.model)
38
+ expect(subject.posts).to eq subject.collection
39
+ end
40
+
41
+ it 'defines edit_params' do
42
+ expect(subject.edit_params).to be_present
43
+ end
44
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,25 +1,106 @@
1
- # Configure Rails Environment
2
- ENV['RAILS_ENV'] = 'test'
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
3
+ require 'rspec/rails'
4
+ require 'capybara/rspec'
5
+ require 'codeclimate-test-reporter'
6
+ require 'database_cleaner'
7
+ require 'pry'
3
8
 
4
- require 'bundler/setup'
5
- Bundler.require :default, :development
6
-
7
- require 'controller_resources'
8
-
9
- require File.expand_path('../dummy/config/environment.rb', __FILE__)
10
- # require 'rails/test_help'
9
+ # Perform all DB operations within a transaction.
10
+ DatabaseCleaner.strategy = :transaction
11
11
 
12
+ # Start test coverage reporting
12
13
  CodeClimate::TestReporter.start
13
14
 
15
+ # Clean backtraces
14
16
  Rails.backtrace_cleaner.remove_silencers!
15
17
 
16
18
  # Load support files
17
19
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
18
20
 
19
- # :nodoc:
20
- # module ActiveSupport
21
- # # Load fixtures from the engine
22
- # if TestCase.method_defined?(:fixture_path=)
23
- # TestCase.fixture_path = File.expand_path('../fixtures', __FILE__)
24
- # end
25
- # end
21
+ # Configure RSpec with `--init`-based options.
22
+ RSpec.configure do |config|
23
+ config.use_transactional_fixtures = true
24
+ config.infer_base_class_for_anonymous_controllers = false
25
+
26
+ # rspec-expectations config goes here. You can use an alternate
27
+ # assertion/expectation library such as wrong or the stdlib/minitest
28
+ # assertions if you prefer.
29
+ config.expect_with :rspec do |expectations|
30
+ # This option will default to `true` in RSpec 4. It makes the `description`
31
+ # and `failure_message` of custom matchers include text for helper methods
32
+ # defined using `chain`, e.g.:
33
+ # be_bigger_than(2).and_smaller_than(4).description
34
+ # # => "be bigger than 2 and smaller than 4"
35
+ # ...rather than:
36
+ # # => "be bigger than 2"
37
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
38
+ end
39
+
40
+ # rspec-mocks config goes here. You can use an alternate test double
41
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
42
+ config.mock_with :rspec do |mocks|
43
+ # Prevents you from mocking or stubbing a method that does not exist on
44
+ # a real object. This is generally recommended, and will default to
45
+ # `true` in RSpec 4.
46
+ mocks.verify_partial_doubles = true
47
+ end
48
+
49
+ # These two settings work together to allow you to limit a spec run
50
+ # to individual examples or groups you care about by tagging them with
51
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
52
+ # get run.
53
+ config.filter_run :focus
54
+ config.run_all_when_everything_filtered = true
55
+
56
+ # Allows RSpec to persist some state between runs in order to support
57
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
58
+ # you configure your source control system to ignore this file.
59
+ config.example_status_persistence_file_path = "spec/examples.txt"
60
+
61
+ # Limits the available syntax to the non-monkey patched syntax that is
62
+ # recommended. For more details, see:
63
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
64
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
65
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
66
+ config.disable_monkey_patching!
67
+
68
+ # This setting enables warnings. It's recommended, but in some cases may
69
+ # be too noisy due to issues in dependencies.
70
+ config.warnings = true
71
+
72
+ # Many RSpec users commonly either run the entire suite or an individual
73
+ # file, and it's useful to allow more verbose output when running an
74
+ # individual spec file.
75
+ if config.files_to_run.one?
76
+ # Use the documentation formatter for detailed output,
77
+ # unless a formatter has already been configured
78
+ # (e.g. via a command-line flag).
79
+ config.default_formatter = 'doc'
80
+ end
81
+
82
+ # Print the 10 slowest examples and example groups at the
83
+ # end of the spec run, to help surface which specs are running
84
+ # particularly slow.
85
+ config.profile_examples = 10
86
+
87
+ # Run specs in random order to surface order dependencies. If you find an
88
+ # order dependency and want to debug it, you can fix the order by providing
89
+ # the seed, which is printed after each run.
90
+ # --seed 1234
91
+ config.order = :random
92
+
93
+ # Seed global randomization in this process using the `--seed` CLI option.
94
+ # Setting this allows you to use `--seed` to deterministically reproduce
95
+ # test failures related to randomization by passing the same `--seed` value
96
+ # as the one that triggered the failure.
97
+ Kernel.srand config.seed
98
+
99
+ config.before do
100
+ DatabaseCleaner.start
101
+ end
102
+
103
+ config.after do
104
+ DatabaseCleaner.clean
105
+ end
106
+ end
@@ -0,0 +1,31 @@
1
+ class TestController
2
+ Params = Struct.new :parameters
3
+
4
+ def self.expose(name, options = {})
5
+ define_method name do
6
+ if name == :post
7
+ Post.all.first
8
+ else
9
+ Post.all
10
+ end
11
+ end
12
+ end
13
+
14
+ def self.permit(*params)
15
+ end
16
+
17
+ def self.decent_configuration(&block)
18
+ end
19
+
20
+ def self.helper_method(*args)
21
+ end
22
+
23
+ def request
24
+ Params.new parameters: {}
25
+ end
26
+
27
+ def params
28
+ {}
29
+ end
30
+ end
31
+