spec
|--- apis #do not put into controllers folder.
|--- your_api_test_spec.rb
|--- controllers
|--- models
|--- factories
|--- views
- Assigning an object to a
belongs_toassociation does not automatically save the object. It does not save the associated object either.
- When you assign an object to a
has_oneassociation, that object is automatically saved (in order to update its foreign key). - In addition, any object being replaced is also automatically saved, because its foreign key will change too
- If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
- If the parent object (the one declaring the
has_oneassociation) is unsaved (that is,new_record?returns true) then the child objects are not saved. They will automatically when the parent object is saved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DROP TABLE IF EXISTS survey_sessions; | |
| -- Imagine a table with survey sessions | |
| -- token: some id or token to access a survey | |
| -- answers: a key value store for answers | |
| CREATE TABLE survey_sessions ( | |
| token text, | |
| answers hstore); | |
| -- We need some data to play with | |
| INSERT INTO survey_sessions (token, answers) VALUES ('9IaxxP', 'a=>1, b=>2'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gem 'pg' | |
| group :development do | |
| gem 'ruby-debug' | |
| end | |
| gem 'rake', '~> 0.8.7' | |
| gem 'devise' | |
| gem 'oa-oauth', :require => 'omniauth/oauth' | |
| gem 'omniauth' | |
| gem 'haml' | |
| gem 'dynamic_form' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| Template Name: Landing | |
| */ | |
| // Add custom body class to the head | |
| add_filter( 'body_class', 'add_body_class' ); | |
| function add_body_class( $classes ) { | |
| $classes[] = 'landing-page'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Integer | |
| N_BYTES = [42].pack('i').size | |
| N_BITS = N_BYTES * 16 | |
| MAX = 2 ** (N_BITS - 2) - 1 | |
| MIN = -MAX - 1 | |
| end | |
| p Integer::MAX #=> 4611686018427387903 | |
| p Integer::MAX.class #=> Fixnum | |
| p (Integer::MAX + 1).class #=> Bignum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'spec_helper' | |
| require 'rake' | |
| RSpec.describe Api::V1::PostsController, :vcr, record: :new_episodes, :type => :api do | |
| context "elastic search test", elasticsearch: true, commit: true do | |
| before do | |
| @post = FactoryGirl.create(:post, first_name: "August", last_name: "Rush", email: "[email protected]", event: "Rock Concert") | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RSpec.configure do |config| | |
| #config.before(:suite) do | |
| # DatabaseCleaner.clean_with(:truncation) | |
| #end | |
| #config.before(:each) do | |
| # DatabaseCleaner.strategy = :transaction | |
| #end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This file was generated by the `rails generate rspec:install` command. Conventionally, all | |
| # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. | |
| # The generated `.rspec` file contains `--require spec_helper` which will cause this | |
| # file to always be loaded, without a need to explicitly require it in any files. | |
| # | |
| # Given that it is always loaded, you are encouraged to keep this file as | |
| # light-weight as possible. Requiring heavyweight dependencies from this file | |
| # will add to the boot time of your test suite on EVERY test run, even for an | |
| # individual file that may not need all of that loaded. Instead, make a | |
| # separate helper file that requires this one and then use it only in the specs |