What code gets run when you run "rails generate scaffold"? - ruby-on-rails

My question is as simple is that: what code (in the Rails codebase) gets run when you run the rails generate scaffold command? I don't really know how I'd go about figuring that out.
(P.S. The reason I'm interested in this is because I want to track down what I believe to be an esoteric bug in Rails.)

See if this gets you on your way: https://github.com/rails/rails/search?q=scaffold&ref=cmdform

Related

How to convert rails app to test files?

I like to create rspec test from working rails 5 app.
It' could be template to work on.
For example:
-scaffold will create test files template which is nice.
-Or simplecov to help increase test ratio (if I understand correctly)
-So if any tools that could run through each line of controller method and re-create each expected/result put in the test file.
Are there any gem or solution ?
Why ask this question?.
I understand this is not a purpose of test. However test is to save time in future and now as well. Many rails app don't have test, and to go back each line of running code will cost again, assuming the app is good at this stage. If we can have all test at this point and use it to control / run for future development that would be good
I found another gem that answer my question
rspec-kickstarter
But to use with Rails 5 it need to edit the path that created.

Rails generate scaffold creates blank controller

The last couple of times that I've used 'rails generate scaffold [ModelName]' everything has been generated except that the controller is blank. It contains no methods at all. It's easy enough to copy that in from other sources, but I'm wondering what is going on.
The only unique thing about this application for me is that it's using the ActiveAdmin gem.
Any suggestions for how I could get this working as expected again?
+1 to hajpoj, but there are a couple additional steps you could use to troubleshoot.
What does rails generate scaffold_controller give you? My first suggestion to be to isolate the controller generator and go from there.
Following that, I would actually look in the Rails generator code at the point of controller generation and work backwards from there. Here is (I believe) the entry point, from there, you can follow the code to where things are failing. This is, obviously, not the easiest path, but would probably teach you a lot about the rails internals.

how would I go about 'starting over from scratch' with Rails tests?

I have an existing Rails app that I built using Rails 3, Mongoid/Mongodb and Devise. The app is running fine. I'd now like to add some tests to it (sure, shoulda done this in the beginning but the learning curve for just Rails was enough...).
I've used several pages to get it going, especially the Rails guide and this blog post about Mongo and Cucumber/Rspec. My concern here is that between all of the "add this to this and such file" that I've done to try and get this working (and it's not) I've made such a mess of things that it might be better to start over from scratch. With the testing portion of the app.
I thought I would just delete the spec and test directories and re-gen the tests but I can't find a command to do that (the regen).
I've built a very simple test (assert true) but I'm getting:
D:/Dev/TheApp/test/test_helper.rb:10:in `<class:TestCase>':
undefined method `fixtures' for ActiveSupport::TestCase:Class (NoMethodError)
I think the real issue here is that I'm using MongoDb and the test architecture in Rails seems to really really want to do ActiveRecord. Not sure if those two are compatible.
Is there a quick way to build a barebones test directory? My short term solution is to just roll back those directories. Hoping for a better solution.
The blank tests are really worthless. If you didn't have tests/specs of value, then just start from scratch. And if you want to start over, you should just delete them and start new.
You could treat your code as "legacy code" as defined by Michael Feathers in Working Effectively with Legacy Code -- that is, code without tests.
Take a look at this getting started with rails testing guide over at 10gen:
http://www.mongodb.org/display/DOCS/Rails+-+Getting+Started#Rails-GettingStarted-Testing

What does "rake test:functionals" do?

I am brand new to ruby, and am starting to build a little shopping cart app, as a basic introduction. I was editing a test file, in the directory /test/functional/ but made a typo and hit enter, after typing "rake test:functionals" into the CLI.
I don't know enough about what this does, or how I can go back to where I was before. When I first tried it, everything was fine, but then when I tried to add some additional functionality it fell apart.
"rake test:functionals" is to run all your rails functional tests which are testing the rails controllers functionality.
You can look at rails guide on testing for further information, the link also explain other kind of test in rails.

Just started a new spree app, but can't find a way to generate theme_default

Anyone know how to generate a default_theme so that it can be edited? It seems that all the core files are hidden and uneditable.
The last working spree app I made started with theme_default exposed under vendor/plugins.
Because this one is in Rails3, I pulled it right from the official railsdog git, thus no theme_default, and no haml.
I'm probably missing something obvious. Any ideas?
Basically, to create your own views, the starting point is to create our own extension. You can achieve this with the command you'll find here:
http://spreecommerce.com/documentation/extensions.html#creatingan-extension
Then it's like any raRails Engine, you can create the views you want, they'll override spree's.
Is rake sandbox what you are looking for? See Building a Sandbox Application
You only do rake sandbox just for test purpose, I have found this link
Change the command for rails g spree:extension [ext_name].

Resources