This file contains 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
#INNER JOIN | |
#An 'inner join' is the most common join operation used in applications | |
#and can be regarded as the default join-type. Inner join creates a new result table | |
#by combining column values of two tables (A and B) based upon the join-predicate. | |
#The query compares each row of A with each row of B to find all pairs of rows which satisfy the join-predicate. | |
SELECT * FROM employee | |
INNER JOIN department | |
ON employee.DepartmentID = department.DepartmentID; | |
#LEFT JOIN |
This file contains 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
#Migration | |
add_column :projects, :tasks_count, :integer, :default => 0 | |
Project.reset_column_information | |
Project.find(:all).each do |p| | |
Project.update_counters p.id, :tasks_count => p.tasks.length | |
end | |
#Model | |
belongs_to :project, :counter_cache => true |
This file contains 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
/* Large desktop */ | |
@media (min-width: 1200px) { | |
} | |
/* Portrait tablet to landscape and desktop */ | |
@media (min-width: 768px) and (max-width: 979px) { | |
} | |
This file contains 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
#Querys | |
Foo.order("published_at desc").limit(10) | |
Foo.where("published_at <= ?", Time.now).includes(:comments) | |
Foo.order("published_at").last | |
#Group by | |
Foo.order("DATE(start_at)").group("DATE(start_at)").count | |
Team.where(name: 'Justice League').first_or_create! |
This file contains 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
#Navigating | |
visit('/projects') | |
visit(post_comments_path(post)) | |
#Clicking links and buttons | |
click_link('id-of-link') | |
click_link('Link Text') | |
click_button('Save') |
This file contains 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
empty? #True if the array is empty | |
first #The first value in the array | |
include? #True if the array includes the given value | |
index #The index number of a given value | |
inspect #The array in a printable format | |
last #The last value in the array | |
length #The number of items in the array | |
reverse #The array in reverse order | |
sort #The array sorted | |
uniq #The unique values in the array |
This file contains 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
# link_to 'Export', messages_path(format: :csv) | |
describe 'CSVoutput' do | |
it "returns a CSV file" do | |
get :index, format: :csv | |
expect(response.headers['Content-Type']).to have_content 'text/csv' | |
end | |
it 'returns content' do | |
create(:message, | |
name: 'Aaron', |
This file contains 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
describe 'GET#show' do | |
it "renders the :show template for the appointment" do | |
contact = create(:contact) | |
appointment = create(:appointment, contact: contact) | |
get :show, id: appointment, contact_id: contact.id | |
expect(response).to render_template :show | |
end | |
end |
This file contains 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
describe "PUT flag_as_inappropriate" do | |
before :each do | |
@message = create(:message) | |
end | |
it "marks the message as inappropriate" do | |
put :flag_as_inappropriate, id: @message | |
@message.reload.is_inappropriate?.should be_true | |
expect(@message.reload.is_inappropriate?).to be_true | |
end |
This file contains 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
describe 'DELETEdestroy' do | |
before :each do | |
@message = create(:message) | |
end | |
it "deletes the message" do | |
expect{ | |
delete :destroy, id: @message | |
}.to change(Message,:count).by(-1) | |
end |