Testing with dependencies from other gem - ruby-on-rails-4

I want to add functionality to the default User model from the solidus_auth_devise gem and I want to write a test for it in Rspec. However, when I try to instantiate a model with Spree::User.new, I would get uninitialized constant Spree What do I have to require to link in the Model from the gem?

Related

Customize Admin template in Shoppe

I am working on a Rails project to build an E-commerce website. I am using Shoppe gem. I refer Tryshoppe website.
As shoppe gem mounts an Admin interface for us but as per my requirements I want to customize it. I am also interested in changing the layout of admin interface.
For example, We can generate views in Device gem and customize it.
Can we generate views and mailer templates to override the default template of Shoppe gem?
To my knowledge the only way would be to clone the gem repo to your github and edit the gemfile as needed. Then add the gem to your app but link it to your github repo for that gem.
This would basically translate to:
gem 'shoppe', :git => 'git://github.com/<username>/shoppe.git'
There is overriding decorators exist in Rails also for such cases:
http://guides.rubyonrails.org/engines.html#improving-engine-functionality

Rails 4 undo "rails destroy MODEL"

I was installing Devise into my Rails 4 application and misread the line in the wiki that talks about generating devise as a new model. I thought I needed to add it to each of my existing models. I used "rails g devise messages" to install devise in my messages model then realized that I was doing it wrong. So I used rails g devise messages to remove devise. This command got rid of my messages model entirely (the model that the whole app is built around). I have looked all over for how to reverse this but can't seem to find anything. I tried running rake db:rollback but it only rolled back my previous installs.
PLEASE tell me that there's some way to retrieve the model, views, controller and 300+ entries!
Thanks for the help!

Overriding routes in the Clearance gem

I'm using the clearance gem to add authentication to a rails app. I would like to use a different layout called 'session' with the sessions and passwords controllers. In order to do this I'll need to override the sessions and passwords controllers, but so far I can't get either of them to use my alternative layout.
I've added a sessions controller that inherits from clearance and my layout file is in the correct place.
class SessionsController < Clearance::SessionsController
layout 'session'
end
I've done the same as above with the passwords controller. Now I add a route that I hoped would override the one that the clearance gem uses:
resource :session, controller: 'sessions'
But this has no effect and the application layout is used. How can I use a different layout with these controllers?
Overriding the layouts is simpler than this: See: https://github.com/thoughtbot/clearance#overriding-layouts
Clearance::PasswordsController.layout 'my_passwords_layout'
Clearance::SessionsController.layout 'my_sessions_layout'
Clearance::UsersController.layout 'my_admin_layout'

what is the best way to create a comment model for my rails social app

I have a user model using devise as its authentication, a post model and are both associated with belongs_to and has_many. I want to include a third model which allows users to comment on posts.
Is it best to create this with act_as_commentable gem or should i create this from scratch using rails version 4.2?

In Rails 4.0.3, how do i create devise users in a seeds.rb file or in a console when protected_attributes is enabled and when it is disabled

Currently using Rails 4.0.3 and the latest version of Devise.
I am trying to automate the creation of a few users through a seeds.rb file in development and production.
I have currently added the gem 'protected_attributes' to my Gemfile to help with porting existing code from Rails 3.x to 4.x. and have used 'attr_accessible' for relevant fields for other entities in my data model.
I tried to create a Devise User through the rails console:
$ rails c
Loading development environment (Rails 4.0.3)
User.create(:email => 'raj#example.com', :password => 'password', :password_confirmation => 'password')
WARNING: Can't mass-assign protected attributes for User: email, password, password_confirmation
As the warning notes, Strong Parameter Support in Rails 4 stops this. (Even though the rails console mentions this as a warning, no data is entered into the corresponding User table)
I tried this with both 'attr_accessible' on the :email, :password, :password_confirmation fields and with the specific line commented out and get a similar error.
I am able to create a devise user when i comment out 'protected_attributes' gem in my Gemfile and comment out the 'attr_accessible' line in my User model but i lose the ability to seed other entities programmatically.
Currently most posts dealing with Rails 4, Strong Parameters, Devise are geared towards creating and manipulating users through a Web Interface. Correspondingly most of the posts on creating Devise Users through code seem to focus on Rails 3 and earlier version.
Any help would be greatly appreciated.