Saturday, 16 March 2019

How to copy local files to remote server & remote server files to local system in ubuntu?

Copy local files to remote server(192.168.1.1)

 $ scp -r /home/rajkumar/Desktop/test ubuntu@192.168.1.1:/var/www/html/Projects/


Copy remote server(192.168.1.1) files to local system

$ scp -r username@domain:/var/www/html/Projects/test /home/rajkumar/Desktop 


 
 Copy local files to remote server(aws ec2)

$ scp -i "test.pem" /home/rajkumar/Desktop/rajkumar username@domainname:/var/www/html/Projects/


  Copy remote server(aws ec2) files to local system

$ scp -i "test.pem" -r username@domainname:/var/www/html/test/rajkumar /home/rajkumar/Desktop



Thursday, 14 March 2019

How to write RSpec for Rails model?

RSpec for model

1. Add the below gem in your Gemfile and run "bundle install"
    gem 'rspec-rails' 

2. To generate spec folder run the below command
    rails generate rspec:install

3. To generate spec for specific model run the below command
    rails g rspec:model Address

4. To write the spec test cases, add the below codes in "spec/address_spec.rb"
RSpec.describe Address, type: :model do
  it 'Belongs to Builder' do
    add = Address.new
    builder = Builder.new
    builder.addresses << add
    expect(add.builder).to be builder
  end
end


5. To run spec for all 
    bundle exec rspec

6. To run spec for specific model
    bundle exec rspec spec/models/address_spec.rb

7. To run spec with html format output.
    rspec spec/models/address_spec.rb --format h > output.html
 


Tuesday, 12 March 2019

How to get the hash key and value in ruby?


How to get the hash value using hash key in ruby

a = {1=>"Active", -1=>"Inactive", 0=>"Under Review"} 

a[1] # 'Active'

a[-1] # 'Inactive'

a[0] # 'Under Review'


How to get the hash key using hash value in ruby 


a = {1=>"Active", -1=>"Inactive", 0=>"Under Review"} 

a.key('Active') #1

a.key('Inactive') #-1

a.key('Under Review') #0

Interactor in Rails

What is interactor? Interactor provides a common interface for performing complex user interactions An interactor is a simple, sin...