RailsCasts Pro episodes are now free!

Learn more or hide this

xanview's Profile

GitHub User: xanview

Comments by xanview

Avatar

In the latest version of rspec, I'm getting errors like:

ruby
  1) Permission as guest allows sessions
     Failure/Error: should allow(:sessions, :new)
     ArgumentError:
       wrong number of arguments (2 for 1)
     # ./spec/models/permission_spec.rb:20:in `block (3 levels) in <top (required)>'
     # -e:1:in `<main>'

It seems the matcher is not valid anymore?

ruby
RSpec::Matchers.define :allow do |*args|
  match do |permission|
    permission.allow?(*args).should be_true
  end
end

How would you rewrite it so that it works with the latest rspec?

Avatar

I don't think this is a good idea. What if a user changes a password because it was compromised? - You would need to change the member ID to log them out which is a really bad idea.

Avatar

What about controller testing? - I have a bunch of integration tests with capybara which are great, but not sure how to write the controller tests.

Avatar

I have this test which is taking 5 seconds to run:

ruby
  describe "GET /event/id" do
    it "allows flagging an event", js: true do
      create(:recording, event: user_event)
      visit event_path(user_event)
      page.should_not have_content("Unflag")
      click_link "toggle_flag"
      page.should have_content("Unflag")
      user_event.reload.flagged.should be_true
    end
  end

How would I speed up a test like that? -- I'm using poltergeist with phantomjs and all js: true tests are painfully slow :(

Avatar

Anyone have an example of how would you write a spec or test something like this?

Avatar

This railscasts doesn't cover how to handle config.action_controller.asset_host which is used when emailing for instance.

You want the email to link to the asset in the correct subdomain.

The solution I'm thinking to use looks like this:

ruby
config.action_controller.asset_host = Proc.new { |source, request = nil, *_|
  top_level = request.subdomain.split('.')[-1]
  domain = CONFIG['domain']
  '#{top_level}.#{domain}'
}

Though I'm not quite sure how to write a test for this.

Avatar

I only have my iPad with me. I opened your learnalist site and while it looks great it seems to be quite glitchy on the iPad. The menu floats about 20% from the top of the screen, it seems to resize every so often, every page seems to freeze and become unresponsive on load or when scrolling. While I see you have an iPad app, it seems to be a recurring theme that more complex sites with loads of bindings (ahem gmail ahem) seem to not work well or at all on tablets and lower performance devices. Something to keep in mind.

Also, can you please give us some examples of client side features learnalist has that would otherwise be messy to implement manually with something like jquery?

Not trying to belittle your website btw, I will be sure to open it from a PC later and I'm sure my experience will be great :)

Avatar

How would you use this authorisation logic with Devise?

I tried:

module Permissions
  class GuestPermission < BasePermission
    def initialize
      allow :devise_sessions, [:new, :create, :destroy]
      allow :sessions, [:new, :create, :destroy]
      allow :user_sessions, [:new, :create, :destroy]
    end
  end
end

But a guest is never able to login :(

Avatar

I fixed the problem by adding this:

ruby
  task :setup do
    run "mkdir -p #{shared_path}/config"
    template "application.yml.erb", "#{shared_path}/config/application.yml"
  end
  
  before 'deploy:assets:precompile' do
    run "ln -s #{shared_path}/config/application.yml #{release_path}/config/application.yml"
  end

woo :)

Avatar

How did you do it?

I have this in my deploy recipe:

ruby
    run "mkdir -p #{current_path}/config"
    run "mkdir -p #{release_path}/config"
    run "mkdir -p #{shared_path}/config"
    template "application.yml.erb", "#{current_path}/config/application.yml"
    template "application.yml.erb", "#{release_path}/config/application.yml"
    template "application.yml.erb", "#{shared_path}/config/application.yml"

When I do cap deploy:setup, it copies the file to:

ruby
    /home/deployer/xanview-portals/demo1/current/config/application.yml
    /home/deployer/xanview-portals/demo1/releases/20121031020720/config/application.yml
    /home/deployer/xanview-portals/demo1/shared/config/application.yml

But when I do cap deploy:cold I see:

ruby
    2012-10-31 02:08:20 executing `deploy:assets:precompile'
    executing "cd /home/deployer/xanview-portals/demo1/releases/20121031020819 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
    servers: ["zanview.com"]
    [zanview.com] executing command
    [out :: zanview.com] rake aborted!
    [out :: zanview.com] No such file or directory - /home/deployer/xanview-portals/demo1/releases/20121031020819/config/application.yml

And it dies :( - Any ideas?

Avatar

Since the main check is in the application controller the permission logic feels like a controller to me, why not permissions_controller.rb in the controllers directory? - it just doesn't feel like a model to me. Is it just me?

Avatar

Does creating a new category belong in the model? - It seems a bit weird to have it in the model rather than the controller, or is it just me?

Avatar

Yes, it looks like CanCan can be implemented in around 100 lines of code when using Strong Parameters! < https://github.com/colinyoung/cancan_strong_parameters

Avatar

CanCan seems to have a big flaw by not handling mass assignment: https://github.com/ryanb/cancan/issues/571

There is this very interesting Gem that is basically around 100 lines of code using Strong Parameters: https://github.com/colinyoung/cancan_strong_parameters

Avatar

Figured it out, seems the haml templates don't look as pretty as the erb ones :(

Avatar

Something is wrong, I am running the rails g bootstrap:themed but I don't get the nice action buttons in the list view and when I click on an item, the delete action button is not red. Any ideas? :/

Looking at the source, the action buttons are just = link_to "Show", oximetry_path(oximetry), etc in link view. My bootstrap version is 2.0.3.

Avatar

A revisited episode of this would be fantastic as well as a look at alternatives :)

Avatar

Would love something like this where mongoid is used :)

Avatar

Useless to anyone outside of the US :(

I was very excited about this, but when I contacted Stripe, they said they will let me know when they will be available in Europe (England in my case) but I'm not holding my breath.

Avatar

Maybe gem 'turn', :require => false -- it should pretty printe test output

Avatar

Seems simple_form has quite a few bugs with Mongoid and doesn't work properly at all - the authors simply say "we don't use mongoid, we don't care" :( - Any alternatives that work well with Mongoid?