Git Product home page Git Product logo

focused_controller's People

Contributors

alsemyonov avatar andyw8 avatar dyba avatar jonleighton avatar joshk avatar leejarvis avatar luke8086 avatar shingara avatar spectator avatar tekin avatar timcowlishaw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

focused_controller's Issues

RSpec and included member routes in a resource

Given the following routes

focused_controller_routes do
 resources :posts do
  get :something, on: :member
 end
end

and the following functionnal test

require 'spec_helper'
require 'focused_controller/rspec_functional_helper'

describe PostsController do
  include FocusedController::RSpecFunctionalHelper

  describe PostsController::Something do
    it "should not raise an error" do
      get
    end
  end
end

I got the this error

 1) PostsController PostsController::Something should not raise an error
     Failure/Error: get
     ActionController::RoutingError:
       No route matches {:controller=>"posts_controller/something", :action=>"call"}

This action works perfectly when accessed via a browser and routes seem to be correctly defined when running rake routes

Rails 4?

Hey Jon,

Any plans to make this rails4 compatible? I added an appraisal and the tests don't run.

I'm happy to take a look as well, but I just got started with rails4, so it may take me some time to get up-to-speed.

Instance variables not available in template

Instance variables set in call are not available in template.

module FooController
  class Bar < Action
    def call
      @foo = 'foofoo'
    end
  end
end

bar.html.erb

<%= @foo.inspect %>

Outputs 'nil'.

Why :run instead of :call

I'm wondering if you'd considered using :call instead of :run for the method name that does the rendering?

undefined method `expose'

After debugging by forking from master and using my own local repo copy, it turns out that expose as described in the README is not supported by the latest published gem.

Warning to all: use only the master directly for now.

Consider removing custom assertions

Look into whether it's possible/practical to remove e.g. assert_redirected_to foo in favour of assert_equal foo, response.redirected_url.

Tests don't run

The travis-ci tests haven't passed in a while. I attempted to run the test locally, but they wouldn't run cleanly (or finish for that matter).

In general, do you plan to keep this project under active development? (I'd be willing to help maintain in either case)

Readme improvement

Took me a while to figure out that I had to put the focused_controller_routes do within the outer draw do and not replace it.
Please provide a small but complete example of a routes.rb file using the new syntax and extra sugar, such as draw, perhaps with an example of a file structure, with the external routes file. Thanks!

DSL syntax

@avdi has proposed a DSL syntax: https://gist.github.com/3757036

I initially resisted adding a DSL to FC because:

  • I didn't want to obscure "what lies beneath" too much
  • I don't find the existing syntax too hard to swallow
  • I didn't want people to think that FC is so different from "ordinary" controllers when it isn't.

However, I am coming around to the idea:

  • Everyone loves a DSL and if this makes some people keener to use FC that's good with me
  • It can be purely optional and we can make "what lies beneath" clear through documentation
  • It can allow new patterns of reuse, such as "full controller inheritance" where every action in one controller is inherited from every action in another. This could be useful for fast prototyping, for example.

But let's go one step at a time and get something working, try it out in real applications, then iterate.

I like Avdi's syntax, but have some comments:

  • BenefitsController = FocusedController::Controller.new do is a bit "out there" I think, and using techniques that people might find confusing.
  • There needs to be a syntax for inheriting actions. For example I usually make create inherit new and update inherit edit. So here's my stab at it:
FocusedController.define :posts do
  common do
    before_filter :authorize
  end

  action :index do
    expose(:posts) { Post.all }
  end

  action :new do
    expose(:post) { Post.new }
  end

  action :create, extends: :new do
    def call
      post.update_attributes params[:post]
      redirect_to posts_path
    end
  end

  shared :find do
    expose(:post) { Post.find params[:id] }
  end

  action :show, extends: :find
  action :edit, extends: :find

  action :update, extends: :edit do
    def call
      # ...
    end
  end

  action :destroy, extends: :find do
    def call
      post.destroy
      redirect_to posts_path
    end
  end
end

I am not sure about the shared thing. An alternative is:

  group do
    expose(:post) { Post.find params[:id] }

    action :show
    action :edit

    action :update, extends: :edit do
      def call
        # ...
      end
    end

    action :destroy do
      def call
        post.destroy
        redirect_to posts_path
      end
    end
  end

Not sure about that either.

Alternatively edit, update and destroy could technically just extend show, but that feels a bit wrong conceptually although it seems fine pragmatically and is less verbose.

Routing rspec matcher doesn't works

On my project I have a route :

focused_controller_routes do
  resources :urls
end

I want test it on my rspec routing like :

describe "url resource" do
  it 'should see /urls' do
    get('/urls').should route_to(
      :controller => 'urls::index',
      :action => 'run'
    )   
  end 
end

But it's failed :

  1) url resource should see /urls
     Failure/Error: get('/urls').should route_to(
       No route matches "/urls"
     # ./spec/routing_spec.rb:5:in `block (2 levels) in <top (required)>'

Rails 4.2

Hello,

are you planning on allowing to use focused controller with Rails 4.2?

Named routes

The focused_controller_routes helper appears to not support the as: 'named_route' construct:

focused_controller_routes do 
  get '/login'  =>  'sessions#new',     as: 'login' 
  get '/logout' =>  'sessions#destroy', as: 'logout' 

  resources :sessions 
end

rake routes:

       login GET    /login(.:format)                           sessions#new
      logout GET    /logout(.:format)                          sessions#destroy
    sessions GET    /sessions(.:format)                        SessionsController::Index
             POST   /sessions(.:format)                        SessionsController::Create
 new_session GET    /sessions/new(.:format)                    SessionsController::New
edit_session GET    /sessions/:id/edit(.:format)               SessionsController::Edit
     session GET    /sessions/:id(.:format)                    SessionsController::Show
             PUT    /sessions/:id(.:format)                    SessionsController::Update
             DELETE /sessions/:id(.:format)                    SessionsController::Destroy

@jonleighton provided a workaround on the mailing list, which works well:

focused_controller_routes do
  get '/login'  =>  'SessionsController::New',     as: 'login'
  get '/logout' =>  'SessionsController::Destroy', as: 'logout'

  resources :sessions
end


       login GET    /login(.:format)                           SessionsController::New
      logout GET    /logout(.:format)                          SessionsController::Destroy
    sessions GET    /sessions(.:format)                        SessionsController::Index
             POST   /sessions(.:format)                        SessionsController::Create
 new_session GET    /sessions/new(.:format)                    SessionsController::New
edit_session GET    /sessions/:id/edit(.:format)               SessionsController::Edit
     session GET    /sessions/:id(.:format)                    SessionsController::Show
             PUT    /sessions/:id(.:format)                    SessionsController::Update
             DELETE /sessions/:id(.:format)                    SessionsController::Destroy

If I can make some time, I'll take a crack at a patch. I took a cursory look at it, but I don't yet understand how it's all working. Any direction someone could provide would be most welcomed.

assert_template only works when explicitly calling render

Whenever I assert the rendering of a template, I need to explicitly call render inside the call method for the specs to pass.

Going down the stack a bit, it seems that the code breaks at test_helper.rb#L126, more specifically, controller._render_options returns nil without an explicit render.

I searched to see if this was expected test/spec behavior, but I couldn't find others having the same problem, so I suspect it to be related to FocusedController.

Test with RSpec and custom render

Hi,

I have the following action

module ConnectorsController
...

class Create < Action
 expose(:connector)

 def call
   @connector = Connector.new(params[:connector])
   @connector.save
   render :json => { :status => 'ok' }
 end
end

If i tried to call it with manually, for example with curl, everything works perfectlly. But when I tried to test it with RSpec

 Failure/Error: subject.call
  RuntimeError:
    ActionController::RackDelegation#content_type delegated to @_response.content_type, but @_response is nil

Here's the test I used, pretty basic

describe ConnectorsController::Create do
 it "should render JSON" do
  subject.params = { :connector => {} }
  subject.call
  puts response.body
 end
end

I also tried to replace the JSON by render :action => 'show' but without success.

Weird path bug that displays wrong error

Lets say you have these routes:

Blog::Application.routes.draw do
  focused_controller_routes do
    resources :sessions, only: [:new, :create, :destroy]

    resources :accounts do
      resources :posts
      resources :ideas
    end

    root to: "PagesController::Splash"
  end
end

And now you want to link to the idea form:

"Hello, make a new #{link_to "idea", new_account_idea_path}"

Now this will error out, saying:

ActionController::RoutingError (No route matches {:action=>"run"}):
   app/helpers/accounts_helper.rb:19:in `no_ideas_text'
   app/views/accounts/_no_ideas.html.slim:1:in   
      `_app_views_accounts__no_ideas_html_slim___4495721604514828093_70275587376260'
   app/views/accounts/show.html.slim:7:in
       `_app_views_accounts_show_html_slim__1164712277643331339_70275587639940'

The error page is Rail's "bad route error", so it wont even show the last 4 lines of that error just the routing erro text.

The "problem" here is that I forgot to provide an account_id:

new_account_idea_path(account)

But it doesn't recognize that.

Session values accessible, Cookies private?

See the below specification:

context 'For valid authentication' do
  Given { subject.params = { authentication: { email: '[email protected]' } } }
  Given { subject.authentication.stub(:legitimate?).and_return(true) }
  Given { Authentication.any_instance.stub_chain(:user, :id).and_return(1) }
  When { subject.call }

  context 'deletes signup session' do
    Then { subject.session[:signup].should be_nil }
  end

  context 'sets authentication cookie' do
    Then { subject.send(:cookies)[:authentication].should_not be_nil }
  end

  context 'sets authentication cookie' do
    Then { subject.cookies[:authentication].should_not be_nil }
  end
end

The first two pass, the last one fails. I was under the impression that I should be able to access cookie data in my FocusedController specs (I have included FocusedController::RSpecHelper) but only session seems to be available here?

Here is the error stacktrace:

  1) SessionsController SessionsController::Create For valid authentication sets authentication cookie 
     Failure/Error: Then { subject.cookies[:authentication].should_not be_nil }
     NoMethodError:
       private method `cookies' called for #<SessionsController::Create:0x007fc818852f90>
     # ./spec/unit/controllers/sessions_controller_spec.rb:47:in `block (5 levels) in <top (required)>'
     # ./spec/unit/controllers/sessions_controller_spec.rb:47:in `block in Then'

Rails 4.1 support?

Hey Jon, was just wondering if you had rails4.1 support on your roadmap. I tried to add 4.1 support myself, but found it not to be a trivial upgrade. Thanks!

Create a Mailing list about focused_controller

Focused_controller has no Mailing list to speak about it and debate like do by wycats and jonleighton on twitter.

Please create an open mailing list to speak about concept behind focused_controller.

Thanks

Controller params not fill

If I check the params fill in my controller. the controller is not fill like do in Rails way. If I do a params[:controller] on my controller, it's return nil.

I think it's better to return the controller name.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.